How to get unix timestamp from a DateTime object in the last hour before switching DST to PHP?

There is sample code

<?php $dt = new \DateTime(); $dt->setTimezone(new \DateTimeZone('Europe/London')); $timestamp = 1351383400; echo "$timestamp \n"; $dt->setTimestamp($timestamp); echo $dt->getTimestamp(); 

which displays 2 different timestamps 1351383400 (Sun, Oct 28, 2012 01:16:40 +0100, just before switching DST) and 1351387000 (Sun, October 28, 2012) 01:16:40 +0000, 1 hour after the switch DST)

The question is, how can I get the timestamp receiver to return the exact same integer that was passed to line 1 of the Timestamp line before?

PHP 5.3.6

+8
php datetime unix-timestamp dst
source share
1 answer

Hope this helps:

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

Output: 1181503727 1181503727

+2
source share

All Articles