日光节约在php中是如何工作的(php和hhvm之间的区别)?
我需要检测时间戳是否为夏令时 我正在使用以下代码测试功能:日光节约在php中是如何工作的(php和hhvm之间的区别)?,php,datetime,timezone,dst,hhvm,Php,Datetime,Timezone,Dst,Hhvm,我需要检测时间戳是否为夏令时 我正在使用以下代码测试功能: <?php date_default_timezone_set('Europe/Berlin'); $timestamp = $baseTimestamp = 1509234900; // Sunday, 29 October of 2017 1:55:00 GMT+02:00 DST $date = (new DateTime)->setTimestamp($baseTimestamp); echo "DateTime
<?php
date_default_timezone_set('Europe/Berlin');
$timestamp = $baseTimestamp = 1509234900; // Sunday, 29 October of 2017 1:55:00 GMT+02:00 DST
$date = (new DateTime)->setTimestamp($baseTimestamp);
echo "DateTime\t\t| Is in summer \t| Minutes passed\n";
for($i = 0; $i < 70; $i++) {
$date = (new DateTime)->setTimestamp($timestamp);
echo $date->format("Y-m-d H:i:s \t|I") . "\t\t| " . ($timestamp - $baseTimestamp)/60 . "\n";
$timestamp = $timestamp + 60;
}
是的,PHP中有几个长期存在的、未解决的、与DST相关的bug
您似乎找到了这一点:
我想这会奏效的。。。对我来说,这看起来像个虫子。是的,我想是的。试试这个:echo(newdatetime)->setTimestamp(1509235200)->getTimestamp();您将看到它输出一个不同的时间戳。HHVM不这样做。这只在时间戳从未通过DateTime对象时才起作用
function isSummer($timestamp) {
$date = (new DateTime)->setTimestamp($timestamp);
if ($date->format('I') == 1) {
return true;
}
return ($date->getTimestamp() > $timestamp);
}