Welcome Guest, Not a member yet? Register   Sign In
How can I best work with GMT?
#1

[eluser]gunnarflax[/eluser]
If I want users to be able to see the post time on all updates to a site in their own timezone, what do I need to do to achieve that? How will I store the time in the database and how should I load the time? Is Unix timestamps a good way of achieving this?
#2

[eluser]toopay[/eluser]
You can use any datatype, but it is easier working with integer/Unix timestamps, since to get gmt date, you can instantly write
Code:
$GMT_date = gmdate('D, d M Y H:i:s \G\M\T', $unix_time));
without converting or maketime.
#3

[eluser]gunnarflax[/eluser]
Sweet! thanks! If I want to adjust the time to someone living in a timezone +4 and my server is in +1, should I just add the number of seconds to the $unix_time variable?
#4

[eluser]toopay[/eluser]
If you want to get the current date and time, based on GMT, you also could use this :
Code:
$timezone  = -5; //(GMT -5:00) EST (U.S. & Canada)
echo gmdate('D, d M Y H:i:s \G\M\T', time() + 3600*($timezone+date("I")));
#5

[eluser]gunnarflax[/eluser]
Thank you very much for your replies, it's exactly what I was looking for! Smile




Theme © iAndrew 2016 - Forum software by © MyBB