We have a project that is hosted in one time zone (say, Pacific Daylight
Time) but the client wants all time recorded in their time zone (say,
Mountain Time). What is the best way to do this? Any recommendations?
Thanks!
Justin
We have a project that is hosted in one time zone (say, Pacific Daylight
Time) but the client wants all time recorded in their time zone (say,
Mountain Time). What is the best way to do this? Any recommendations?
Thanks!
Justin
Storing time in the database in a zone other than the server’s zone
or UTC is difficult. You probably want to store all times as UTC, and
then convert them to the appropriate zone on output.
An approach that has worked well for me is to store all times in UTC,
build HTML pages in UTC, then use Javascript on the client side to
convert all the times to browser-local time before display.
cf. http://mikewest.org/archive/showing-perfect-time-unobtrusively
Regards,
Danny
These are great answers. Thanks for your help, both of you!
On 03/06/2006, at 4:08 AM, Justin B. wrote:
We have a project that is hosted in one time zone (say, Pacific
Daylight Time) but the client wants all time recorded in their time
zone (say, Mountain Time). What is the best way to do this? Any
recommendations? Thanks!
Storing time in the database in a zone other than the server’s zone
or UTC is difficult. You probably want to store all times as UTC, and
then convert them to the appropriate zone on output.
In environment.rb, you’ll need:
config.active_record.default_timezone = :utc
And then take a look at TZInfo (http://tzinfo.rubyforge.org/) for
doing timezone conversions.
Cheers,
Pete Y.
http://9cays.com/
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs