Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
日光节约在php中是如何工作的(php和hhvm之间的区别)?_Php_Datetime_Timezone_Dst_Hhvm - Fatal编程技术网

日光节约在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);
}