I found something I can't really explain, maybe someone here can give me a hint.
I have the following test code, that prints 2 formatted timestamps, one for the 31.03.2013 and one for 31.03.2014, using date()
and gmdate()
:
<?php
function print_date($timestamp, $year) {
// Add timezone offset for germany
$timestamp += 3600;
print "in $year\n";
print "date: " . date('d.m.Y H:i:s', $timestamp) . "\n";
print "gmdate: " . gmdate('d.m.Y H:i:s', $timestamp) . "\n";
print "\n";
}
$end_2013 = 1364684400; // 31.03.2013
$end_2014 = 1396216800; // 31.03.2014
print_date($end_2013, '2013');
print_date($end_2014, '2014');
print "Default timezone: " . date_default_timezone_get() . "\n";
The result surprises me:
in 2013
date: 31.03.2013 01:00:00
gmdate: 31.03.2013 00:00:00
in 2014
date: 31.03.2014 01:00:00
gmdate: 30.03.2014 23:00:00
Default timezone: Europe/Berlin
Where does the difference in 2014 come from? My first thought is daylight savings time, but why doesn't that have an effect in 2013? Why are there 2 hours difference in 2014 but only 1 hour difference in 2013?
Daylight savings for Berlin starts at
2013 Sunday, 31 March, 02:00
2014 Sunday, 30 March, 02:00
Your specified time value for each date is 00:00 on that date, so for 2013 Sunday, 31 March it is before 2am, so no daylight savings; for 2014 it is after 2am on 30th March
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments