Jump to content

date() function and DST


seanlim

Recommended Posts

Hi guys

Need help with the daylight saving time (DST). Have been tearing my hair out over this for the past hour.

I need PHP to follow the UK timezone, and have therefore added the following line at the start:
[code]putenv("TZ=Europe/London");[/code]

For those who don't already know, the official timezone for London is GMT. As DST is observed in london now, time should be 1 hour forward from GMT i.e. GMT +01:00

PHP's date function can "detect" the DST correctly; date('I') returns 1.

[code]<?
putenv("TZ=Europe/London");
echo "London<br>";
echo "Timestamp: ".time()."<br>";
echo "DST: ".date('I')."<br>";
echo "Time: ".date('H:i O')."<br>";
echo "<br>";
echo "GMT<br>";
echo "Timestamp: ".gmmktime(date('G'), date('i'), date('s'), date('n'), date('t'), date('Y'))."<br>";
echo "DST: ".gmdate('I')."<br>";
echo "Time: ".gmdate('H:i O')."<br>";
?>[/code]

output:
[code]London
Timestamp: 1150213911
DST: 1
Time: 15:51 +0100

GMT
Timestamp: 1151686311
DST: 0
Time: 15:51 +0000[/code]

I am totally confused by the output. I would think that London's time would output 16:51 instead.

Does PHP support fully support DST? Or do I not understand DST enough?

Thanks..
Link to comment
https://forums.phpfreaks.com/topic/11887-date-function-and-dst/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.