php - Managing timezones -


i have gone through many timezone/php posts, , suggest storing datetime fields in utc, using application users timezone offset when storing , displaying datetime information.

the problem have i've inherited application wasn't timezone aware, , need cater this.

the server set "est +11:00 australia/melbourne", , there applications running server. can't change this.

fortunately, know users timezone offset, ie -05:00, etc,.

the application takes javascript dates , parses them using php's strtotime() function , stores in mysql database, this:

$event_starts = date('y-m-d h:i:s',      strtotime('thu dec 02 2010 11:15:00 gmt+1100 (aus eastern daylight time)'); 

so have suggestions best way on how can make application timezone aware considering server isn't set utc?

many thanks, j.

this not going easy.

first of all, consider existing stored dates in local time of server, observes daylight saving time. code has these dates except printing them, or in future, need convert them utc first. if daylight saving rules not same @ point in time date stored , current time (when conversion taking place), server use "current" rules , therefore produce wrong result. granted, scenario may far-fetched in specific case (or again might not), it's strong warning against storing other utc.

assuming dst rules remain constant, , have php >= 5.3.0, can this:

  1. read "original" database date datetime::createfromformat, explicitly specifying timezone (server's tz)
  2. convert user local time datetime::settimezone (specifying user's tz)
  3. display user

when receiving user input, need reverse:

  1. create user local time date with datetime::createfromformat, explicitly specifying timezone (user's tz)
  2. convert server local time datetime::settimezone (specifying server's tz)
  3. store in database

apart above, suggest taking application offline @ point , convert dates in database utc. rid of problem discussed earlier (at least in future, past cannot undone). "server's tz" mention above utc (regardless of fact actual server may set aus edt or not, "working" timezone utc).


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -