What is the most effective way to manage time zones in a PHP/MySQL application? -


i'm developing web application involves use of timestamps. timestamps display in user's time zone little configuration possible. facebook , google calendar both update displayed time automatically when logged different time zones.

what effective method you've used deal time zones in web apps? if @ possible, require no additional input user.

here's i'm thinking far:

  1. store timestamps in database in utc
  2. keep database table correlates time zones utc offsets, , whether daylight savings time observed in time zone
  3. given client information (ip address?), find user's current time zone. information can cached in session variable prevent repeated reads table.
  4. whenever timestamp database displayed, convert using utc offset

i find hard believe there's nothing out there this. if have suggestions, i'd appreciate it.

i'd propose solution:

  1. store dates in mysql timestamp column type
  2. right after connect mysql - specify current user's timezone set time_zone='<tz>' <tz> can either +01:00 offset or timezone name asia/vladivostok (for latter special timezones db should imported dba)

the benefit of using timestamp automatically converts date , utc, according time_zone you've specified in current connection.

more details timestamp: http://dev.mysql.com/doc/refman/5.1/en/timestamp.html

about retrieving current user's timezone (even though there lot of answers here on topic, let's once again):

  1. as long there tz value in cookies (look @ step 4) - use it.
  2. for registered/authenticated users - can ask specify timezone , store permanently in db.
  3. for guests can retrieve timezone javascript (date.gettimezoneoffset()) , send ajax
  4. if first request/nothing passed ajax - guess ip
  5. for each step (1-3) - save timezone cookie.

Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -