Php 如何查找给定时区的DST开始和结束日期?

Php 如何查找给定时区的DST开始和结束日期?,php,date,timestamp,dst,Php,Date,Timestamp,Dst,当当地夏时制即将到来时 2013年11月3日,星期日,02:00:00,时钟倒转1小时至 2013年11月3日星期日,当地标准时间01:00:00 当当地夏时制即将到来时 2013年10月27日,星期日,03:00:00,时钟倒转1小时至 2013年10月27日星期日,当地标准时间02:00:00 如何使用PHP获取这些日期? 例如:如果没有谷歌,我如何获得2014年柏林的日期“2013年10月27日星期日02:00:00;” 如果我有一个unixtimestamp在那一小时内,它会指向第一个


当当地夏时制即将到来时
2013年11月3日,星期日,02:00:00,时钟倒转1小时至
2013年11月3日星期日,当地标准时间01:00:00


当当地夏时制即将到来时
2013年10月27日,星期日,03:00:00,时钟倒转1小时至
2013年10月27日星期日,当地标准时间02:00:00

如何使用PHP获取这些日期?
例如:如果没有谷歌,我如何获得2014年柏林的日期“2013年10月27日星期日02:00:00;”

如果我有一个unixtimestamp在那一小时内,它会指向第一个小时还是最后一个小时?

我想这就是你想要的:

$timezone = new DateTimeZone("Europe/London");
$transitions = $timezone->getTransitions();
我承认,这有点碍眼,如果你对数组中返回多个条目的原因感到困惑,那是因为确切的日期不同,因为在大多数地区,它是基于一个月的一周中的某一天(例如“10月的最后一个星期日”)而不是特定的日期。对于上述情况,如果您只想要即将到来的转换,则应添加timestamp_作为参数:

$timezone = new DateTimeZone("Europe/London");
$transitions = $timezone->getTransitions(time());
您可以获得所有的转换(从PHP5.3开始使用begin和end)

这将在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);
}

unix时间戳的设计单位是UTC,因此它将根据该时区中的当前时间进行调整。UTC不使用DST,这使得它成为存储时间的常数非常方便。