如何在PHP中进行DST切换之前的最后一小时内从DateTime对象中检索unix时间戳?

Ale*_*lex 8 php datetime unix-timestamp dst

有一个示例代码

<?php
$dt = new \DateTime();
$dt->setTimezone(new \DateTimeZone('Europe/London'));

$timestamp = 1351383400;    
echo "$timestamp \n";

$dt->setTimestamp($timestamp);
echo $dt->getTimestamp();
Run Code Online (Sandbox Code Playgroud)

输出2个不同的时间戳1351383400(太阳,2012年10月28日01:16:40 + 0100,DST开关前)和1351387000(太阳,2012年10月28日01:16:40 +0000,1小时后,DST开关后)

问题是如何让Timestamp getter返回我之前传递给Timestamp setter 1行的完全相同的整数?

PHP 5.3.6

小智 2

希望这可以帮助:

    $dt = new DateTime();
    $dt->setTimezone(new \DateTimeZone('Europe/London'));
    $timestamp = 1181503727;
    echo $timestamp . '<br />';

    $dt->setTimestamp($timestamp);
    echo $dt->format('U'); 
Run Code Online (Sandbox Code Playgroud)

输出:1181503727 1181503727