Php 如何在IF语句中正确使用strotime?
我试图检查一个特定的时间条件,但由于某种原因,我无法让它工作。只有第一个条件得到应用。在我看来,第二个条件应该适用,因为已经过了中央时间上午9点59分 我有:Php 如何在IF语句中正确使用strotime?,php,Php,我试图检查一个特定的时间条件,但由于某种原因,我无法让它工作。只有第一个条件得到应用。在我看来,第二个条件应该适用,因为已经过了中央时间上午9点59分 我有: <?php $timezone = date_default_timezone_set('America/Chicago'); $TheDate = strtotime("April 1, 2016, 12:00 am"); if ($TheDate >= strtotime("March 30,
<?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';
}?>
我在两天前测试过这个,它在我们三月份的时候工作,现在我被愚弄了。有人知道答案吗?我仔细研究了代码,并在Charlotte和PHP手册的帮助下,找到了我想要做的事情
我只是添加了time()函数并格式化了time/date参数 还有,最后两行的语法错误。输入是什么?预期产量是多少?实际输出是什么?看看这个0:00<9:59的输出,因此应用了第一个If get。提供的代码的输出是
My name
。您还期望什么?time()
返回当前UNIX时间戳。通过strotime()
(传递的日期/时间字符串的UNIX时间戳)也可以得到什么。