获取即将到来的夏令时日期

Get upcoming Daylight Saving date

如何通过 PHP 为特定时区更改即将到来的夏令时 date/time?我想输出例如:

Upcoming clock change for Berlin will be on 29.10.2017 at 3am.

$date = new DateTime();
$tz = $date->getTimezone();
$changes = $tz->getTransitions(strtotime("yesterday"), strtotime("+1 year"));
$n = count($changes);
$tnow = time();
for($i = 0; $i < $n; $i++)
{
    if($changes[$i]["ts"] > $tnow)
    {
        echo "Upcoming clock change for " . $tz->getName() . " will be on " . $changes[$i]["time"] . "\n";
        break;
    }
}

这感觉有点笨拙,但它测试了 OF。需要一分钟间隔,因为 DST 更改不限于每小时边界。

<?php // demo/temp_g5wx.php
/**
 * 
 */
ini_set('display_errors', TRUE);
error_reporting(E_ALL);

// SET OUR TIME ZONE
$zone_obj = new DateTimeZone('America/New_York');

// USE ONE-MINUTE INTERVALS TO DETECT THE CHANGE
$minute = new DateInterval('PT1M');

// FOMATTING CHARACTER FOR DAYLIGHT SAVINGS TIME
$dst = 'I';

// GET A DATETIME OBJECT TO TEST
$time_obj = new DateTime('Today', $zone_obj);

$old_dst = $time_obj->format($dst);
$new_dst = $old_dst;

// ITREATE BY MINUTES
while ($old_dst == $new_dst)
{
    $time_obj->add($minute);
    $new_dst = $time_obj->format($dst);
}

// SHOW THE MOMENT OF CHANGE LIKE ["date"]=> string(26) "2017-11-05 01:00:00.000000"
var_dump($time_obj);