Jump to content


Photo

Problem converting UTC to GMT.


  • Please log in to reply
1 reply to this topic

#1 eddorey2k3

eddorey2k3
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 20 May 2006 - 11:42 AM

Ok. I have a script that pulls out the time it was run, and puts it into a database. That looks like this.

$date = date("DdSF,Y");
$time = date("g:i:sa");

I have no problem with this, it works fine. However, I do have a problem with the time it pulls out. Whilst it works fine, since it's in UTC and I'm in GMT it is always 5 hours behind. I'm looking for a way to solve this. I've been told that I need to add 18000 seconds to the time (Since that's 5 hours). As far as I can see, this will work, except for DST.

Any ideas how I can either get it to add 18000 all the time, or work out the time for DST as well?

Thanks.

#2 Kris

Kris
  • Staff Alumni
  • Advanced Member
  • 2,755 posts
  • LocationThe Internet

Posted 20 May 2006 - 02:48 PM

As far as I was aware, GMT and UTC are the same thing.

To add 5 hours, you could do it like this. You can add 18000 to the seconds if you prefer though output would be the same.
<?php
echo date("DdSF,Y g:i:sa",mktime(date("g")+5,date("i"),date("s"),date("m"),date("d"),date("Y")));
?>

As for making it DST correct, I guess you could use a switch() to match the current month, and if DST applies add/remove an hour.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users