Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.