| Choosing & Storing Timezones
|
username

msg:4152178 | 4:24 am on Jun 14, 2010 (gmt 0) | Hi all, So I am storing some datetime values in a MySQL db. I am setting the values as the current time according to whatever time it is in UTC (GMT +0). What I want to do is have the user set their timezone i.e Australia/Brisbane, and then the datetime which was stored in UTC time, would display the datetime of that timezone. In the case of this example, we would see: UTC: 2010-06-14 01:00:00 (GMT + 0:00) Australia/Brisbane: 2010-06-14 11:00:00 (GMT + 10:00) I am setting the timzones using the putenv function, but am unsure how to changes a timezone I know was stored in UTC. Your help would be greatly appreciated. Thanks.
|
username

msg:4152179 | 4:28 am on Jun 14, 2010 (gmt 0) | So to clarify, the database would hold: 2010-06-14 01:00:00 (UTC: GMT + 0:00) ..and the front end of the website would show: 2010-06-14 11:00:00 (Australian/Brisbane: GMT + 10:00)
|
Alcoholico

msg:4153744 | 5:44 pm on Jun 16, 2010 (gmt 0) | I use something similar to this function:
## function offset_date ## format; same as php function date ## offset; offset seconds; ie: GMT+3 3*60*60 function offset_date($format, $unix_timestamp, $offset=0) { $unix_timestamp = empty($unix_timestamp) ? time()+$offset : $unix_timestamp+$offset; return @gmdate($format, $unix_timestamp); }
Since your times are in ISO format, you probably find this function handy:
function ISOdate2UNIXtime($ISOdate) { return gmmktime(substr($ISOdate,11,2),substr($ISOdate,14,2),substr($ISOdate,17,2),substr($ISOdate,5,2),substr($ISOdate,8,2),substr($ISOdate,0,4)); }
|
g1smd

msg:4153792 | 8:21 pm on Jun 16, 2010 (gmt 0) | Do you allow for changes caused by DST? You might need a toggle to allow for that. New York is UTC-0500 in their Winter, and UTC-0400 in their Summer. Southern Hemisphere winter occurs during Northern Hemisphere summer, and vice versa. The UK uses UTC+0000 in their Winter and UTC+0100 in their Summer. I would completely avoid the term "GMT". It was replaced by UTC in 1972.
|
|
|