如何在IF语句中正确使用strtotime?

时间:2016-04-01 21:39:58

标签: php

我试图检查特定的时间条件,但由于某种原因我无法让它工作。仅应用FIRST条件。在我看来,应该应用第二个条件,因为它已经过了中部时间早上9:59。

我有:

<?php
$timezone       = date_default_timezone_set('America/Chicago');
$TheDate        = strtotime("April 1, 2016, 12:00 am");


if ($TheDate >= strtotime("March 30, 2016, 12:00 am") && $TheDate <= strtotime("April 1, 2016, 9:59 am")) {
    global $eventMsg;
    echo 'My name';
}

else if ($TheDate >= strtotime("April 1, 2016, 4:12 pm") && $TheDate <= strtotime("April 1, 2016, 4:59 pm")) {
    global $eventMsg;
    echo 'His name';
}

else {
    global $eventMsg;
    echo 'Pete\'s name';
}?>

我两天前对它进行了测试,当我们在三月份的时候它正在工作,现在我被愚弄了。有人有答案吗?

1 个答案:

答案 0 :(得分:0)

我玩了代码,并在夏洛特和PHP手册的帮助下找出了我想要做的事情。

我只是添加了time()函数并格式化了time / date参数。