How to find the date and time daylight savings begins
如果我有用户的时区(例如:澳大利亚/悉尼),如何使用PHP查找夏令时在当地时间开始的日期和时间?
我最终根据这张票的一些代码来处理它。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | $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 '[cc lang="php"]'; print_r($trans); echo ' |
';
代码> PRE>