Page 1 of 1

how to convert a GMT datetime to local datetime?

Posted: Fri Apr 11, 2008 1:48 pm
by WilliamLou
For example:
I got a GMT datetime using : $gmdate = gmdate("Y-m-d H:i");
and then I could save this string into database as a timestamp, however when I show this timestamp on Web, I prefer to show the timestamp in local time, is there some function in php for this purpose? If the function already takes day time saving into account, that would be great.

Re: how to convert a GMT datetime to local datetime?

Posted: Sat Apr 12, 2008 3:29 am
by andym01480
If you are talking about displaying the local time for every user wherever they are - 2 ways

1) Either the user has to specify their timezone and you store that as a cookie and do a php calculation to display it
2) Use javascript to work out the users offset and to calculate the time client side, knowing your servers timezone and the users! - http://www.usingjavascript.com/function ... ffset.html looked a helpful start