Jump to content


Photo

date() function and DST


  • Please log in to reply
2 replies to this topic

#1 seanlim

seanlim
  • Members
  • PipPipPip
  • Advanced Member
  • 355 posts
  • LocationLondon, United Kingdom

Posted 13 June 2006 - 04:05 PM

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:
putenv("TZ=Europe/London");

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.

<?
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>";
?>

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

GMT
Timestamp: 1151686311
DST: 0
Time: 15:51 +0000

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

#2 cat_killer15

cat_killer15
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 13 June 2006 - 10:11 PM

Running the code you have above I got this output:
London
Timestamp: 1150236686
DST: 1
Time: 23:11 +0100

GMT
Timestamp: 1151709086
DST: 0
Time: 22:11 +0000
Is this not what you want it to show?

#3 seanlim

seanlim
  • Members
  • PipPipPip
  • Advanced Member
  • 355 posts
  • LocationLondon, United Kingdom

Posted 14 June 2006 - 08:02 AM

Yes. That's what I want it to show. Problem is, my server is in Singapore where there isn't DST.

maybe putenv is not the best method..

any help here?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users