与getTransitions
您一起获得所有转换(从 php 5.3 开始和结束)
这适用于 PHP < 5.3
<?php
/** returns an array with two elements for spring and fall DST in a given year
* works in PHP_VERSION < 5.3
*
* @param integer $year
* @param string $tz timezone
* @return array
**/
function getTransitionsForYear($year=null, $tz = null){
if(!$year) $year=date("Y");
if (!$tz) $tz = date_default_timezone_get();
$timeZone = new DateTimeZone($tz);
if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
$transitions = $timeZone->getTransitions(mktime(0, 0, 0, 2, 1, $year),mktime(0, 0, 0, 11, 31, $year));
$index=1;
} else {
// since 1980 it is regular, the 29th element is 1980-04-06
// change this in your timezone
$first_regular_index=29;
$first_regular_year=1980;
$transitions = $timeZone->getTransitions();
$index=($year-$first_regular_year)*2+$first_regular_index;
}
return array_slice($transitions, $index, 2);
}