how to convert a GMT datetime to local datetime?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
WilliamLou
Forum Newbie
Posts: 12
Joined: Fri Mar 14, 2008 1:32 pm

how to convert a GMT datetime to local datetime?

Post 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.
User avatar
andym01480
Forum Contributor
Posts: 390
Joined: Wed Apr 19, 2006 5:01 pm

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

Post 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
Post Reply