My goal: To output dates on pages that match the user's timezone.
Why I want this: Records are stored based using GMT. I don't want them thinking a message arrived for them at a different time than they actually arrived. Also the user shouldn't have to perform math to figure out when the message was received.
Recently I was told I should store the date and time in MySQL using the date/time data type so that I can later use MySQL's built in functions to manipulate the data. I can then convert the date to show to the viewer and convert back when storing.
This process has been giving me the most trouble so far.
I've researched for the best way to find the user's timezone and it looks like I'll have to use Javascript for that. I'm unaware how more professional or time tested scripts accomplish this.
The way that I came up with (which doesn't work all too well) is to instead of have PHP print the date to the screen, it hands the date over to Javascript in which Javascript is to get the viewer's timezone, make the change to the date and then Javascript write's the date to the screen.
One problem that I'm running into doing it this way is after the page has been sitting for a few minutes. If I hit refresh the dates jump forward several hours, if I hit refresh again they jump back, again and they'll jump forward. I can keep doing this and watch the hours seesaw back and forth each time I hit refresh. Another problem is that I have yet to figure out how to format a Javascript date so in the date/time field I have this:
Fri Jan 01 2010 22:04:31 GMT-0500 (Eastern Standard Time)
Another way may be to ask the logged in user upon registration what their timezone is and format the dates that way, although many of the more professional sites don't seem to do this and they seem to get the time's right.
I'm sure that many of you have faced the same dillemma, I'm curious how you went about solving this.