Forum Moderators: coopster

Message Too Old, No Replies

Converting time between two different time zones

         

Jeremy_H

6:57 pm on Apr 18, 2006 (gmt 0)

10+ Year Member



In a script, I currently receive my time using $date=date("D M j Y g:i:s a T");

While this works great, I am in a different time zone then my server, and I'm getting tired of having to change the times in my head.

I was thinking about subtracting 1 from "g", since I'm behind one hour. However, I realized this doesnt work well for two hours of each day, when its between 1:00:00 am - 1:59:59 am 1:00:00 pm - 1:59:59 pm. It will also get more complicated when dealing with days, months and even the years during transitional times.

Is there a better way of converting times between time zones?

Thanks

Little_G

7:27 pm on Apr 18, 2006 (gmt 0)

10+ Year Member



Hi,

You can set the time zone using date_default_timezone_set [uk.php.net]

Andrew

Jeremy_H

4:37 pm on Apr 21, 2006 (gmt 0)

10+ Year Member



Thank you very much LittleG, this seems to be exactly what I need.

Unfortunately, I can't get it to work, nor does there seem to be much documentation on it online (even on PHP's site).

Do I just insert this line somewhere into my code, preferable in the top:

date_default_timezone_set(America/Anchorage);

Or do I treat it differently?

Thanks

whoisgregg

4:44 pm on Apr 21, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The PHP manual page on date() [php.net] has a comment of value:

putenv("TZ=EST");
echo date('r');

Jeremy_H

5:51 pm on Apr 21, 2006 (gmt 0)

10+ Year Member



Ahhh, now I see why I won't work. I only have PHP 4.3.11.

Lame. :(

hakre

4:21 pm on Apr 24, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



i think it's possible to add the offset (in seconds) directly to the second parameter of the date function:

$date=date("D M j Y g:i:s a T", now() [i]+/- offset in seconds (=hour * 3600)[/i] );