如何找到夏令时开始的日期和时间

时间:2015-03-03 04:22:00

标签: php datetime

如果我有用户的时区(例如:澳大利亚/悉尼),如何使用PHP查找夏令时在当地时间开始的日期和时间?

1 个答案:

答案 0 :(得分:0)

我最终根据t his ticket的一些代码来处理它。

$tz = new DateTimeZone('Australia/Sydney');
$transitions = $tz->getTransitions();
if (is_array($transitions)) {
    foreach ($transitions AS $k => $t){

        // Look for current year
        if (substr($t['time'],0,4) == date('Y')) {

            // If isdst is set to 1, that means daylight savings starts on this date
            if (!empty($t['isdst'])) {

                $trans = $t;

            // If isdst is empty, that means daylight savings has already started
            // so I'll go back to the previous transition
            } else {

                $prev_k = $k - 1;
                $trans = $transitions[$prev_k];

            }

            break;

        }
    }
}

echo '<pre>';
print_r($trans);
echo '</pre>';