- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在尝试执行一个函数,如果现在处于一周中的特定时间和特定日期之间,该函数将返回 true。
问题是,unix 时间戳似乎不匹配。
<?php
function isWorkingTime() {
$now = new DateTime(date('Y-m-d H:i:00'), new DateTimeZone(date('T')));
$tz = $now->getTimezone();
if(strtolower($tz->getName()) != 'est'){
$now->setTimezone(new DateTimeZone('EST'));
}
$min = clone $now;
$min->setTime(8,30,0);
$max = clone $now;
switch($now->format('N')){
case 1:
case 2:
case 3:
case 4:
$max->setTime(17,30,0);
break;
case 5:
$max->setTime(16,30,0);
break;
default:
return false;
break;
}
return ($now >= $min && $now < $max);
}
?>
如果我继续尝试输出 3 个日期时间对象,如下所示:
<?php
echo 'now: '.$now->format('Y-m-d H:i:s U T').PHP_EOL;
echo 'min: '.$min->format('Y-m-d H:i:s U T').PHP_EOL;
echo 'max: '.$max->format('Y-m-d H:i:s U T').PHP_EOL;
?>
我明白了:
now: 2017-02-15 13:17:00 1487164620 EST
min: 2017-02-15 08:30:00 1487165400 EST
max: 2017-02-15 17:30:00 1487197800 EST
为什么 $min 时间戳大于 $now?
我正在运行 PHP 5.6.30
最佳答案
Docu 指出你不应该使用 EST,并警告“奇怪”的效果:
Warning Please do not use any of the timezones listed here (besides UTC), they only exist for backward compatible reasons, and may expose erroneous behavior.
http://php.net/manual/en/timezones.others.php
使用适当的时区名称(如 America/New_York
)运行您的代码片段不会显示此问题:https://3v4l.org/NR3cg
明确问题/错误:
使用美国东部标准时间: https://3v4l.org/BdUan
02/15/2017 6:00 am 1487138400 -> TS says 02/15/2017 @ 6:00am (UTC) (wrong)
02/15/2017 8:30 am 1487165400 -> TS says 02/15/2017 @ 1:30pm (UTC) (right)
使用美国/纽约: https://3v4l.org/ndISv
02/15/2017 6:00 am 1487156400 -> TS says 02/15/2017 @ 11:00am (UTC) (right)
02/15/2017 8:30 am 1487165400 -> TS says 02/15/2017 @ 1:30pm (UTC) (right)
(虽然一切都应该是相同的时间戳,但与第 2 行比较)
关于具有较早日期时间的 PHP Datetime 对象具有较高的时间戳值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42257178/
我正在尝试用 java 编写具有以下输出的 java 代码。 ---JGRASP exez: java Guess Is the number 50? H Ia the number
如果查看 Azure 存储中磁盘的定价等级(截至目前,美国东部地区的高级 SSD 低于一级),就会发现提供的 IOPS 越高,磁盘大小就越大。 人们可以选择更高的性能层,但使用较小的磁盘大小(尽管这可
如果查看 Azure 存储中磁盘的定价等级(截至目前,美国东部地区的高级 SSD 低于一级),就会发现提供的 IOPS 越高,磁盘大小就越大。 人们可以选择更高的性能层,但使用较小的磁盘大小(尽管这可
我是 azurewebsites 服务的新用户,我很高兴为什么我的网站发送了太多数据。服务器在 8 小时内输出了 55GB 数据。我的网站不包含任何大文件,它只是一个名片网站。我如何检查发生了什么?此
我希望我的 Bootstrap 轮播在图像上方有一个点覆盖。 Carousel Caption 应位于虚线叠加层之上。我无法让它与 z-indexes 一起工作。 我做错了什么吗? (可能安静 :-)
我正在使用动态编程来解决一个问题,其中我将得到 n 并且需要输出最小数量的操作以通过使用这三个操作(-1,/2,/3)从 n 中获得 1。给定约束(1 using namespace std; int
我需要在左右栏之间放置内容,前提是内容 block 高于左右栏 block 。我试着用 float: right;在内容的样式中,它只对齐图中的示例。 如何使列之间的内容 block 居中?我的代码是
我有一个非常简单的网页设置,由 div、标题和 i 元素组成的网格: 我想要做的就是在这个网格后面添加一个带有背景颜色和标题的 div,网格的元素出现在新背景 div 的顶部。 但是,当我尝试这样做时
大家,我是数据科学的新手。我正在使用支持向量回归来解决回归问题。使用网格搜索调整 SVM 参数后,我得到了 2.6% MAPE,但我的 MAE 和 MSE 仍然非常高。 我为mape使用了用户定义的函
我是一名优秀的程序员,十分优秀!