# Best way to handle different time zones?

**URL:** <https://www.ruby-forum.com/t/best-way-to-handle-different-time-zones/62331>\
**Category:** Rails\
**Created:** [June 2, 2006, 8:10pm UTC](https://www.ruby-forum.com/t/best-way-to-handle-different-time-zones/62331 "2006-06-02T20:10:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![vtphysguy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/77aa72/32.png) [@vtphysguy](https://www.ruby-forum.com/u/vtphysguy)\
**Post date:** [June 2, 2006, 8:10pm UTC](https://www.ruby-forum.com/t/best-way-to-handle-different-time-zones/62331/1 "2006-06-02T20:10:11Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![vtphysguy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/77aa72/32.png) [@vtphysguy](https://www.ruby-forum.com/u/vtphysguy)\
**Post date:** [June 3, 2006, 1:42am UTC](https://www.ruby-forum.com/t/best-way-to-handle-different-time-zones/62331/2 "2006-06-03T01:42:10Z")

</div>

> 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](http://mikewest.org/archive/showing-perfect-time-unobtrusively)

Regards,

Danny

---

<div class="post-metadata">

**Author:** ![vtphysguy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/77aa72/32.png) [@vtphysguy](https://www.ruby-forum.com/u/vtphysguy)\
**Post date:** [June 3, 2006, 8:15pm UTC](https://www.ruby-forum.com/t/best-way-to-handle-different-time-zones/62331/3 "2006-06-03T20:15:54Z")

</div>

These are great answers. Thanks for your help, both of you!

---

<div class="post-metadata">

**Author:** ![vtphysguy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/77aa72/32.png) [@vtphysguy](https://www.ruby-forum.com/u/vtphysguy)\
**Post date:** [June 3, 2006, 1:23am UTC](https://www.ruby-forum.com/t/best-way-to-handle-different-time-zones/62331/4 "2006-06-03T01:23:30Z")

</div>

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/](http://tzinfo.rubyforge.org/)) for  
doing timezone conversions.

Cheers,

Pete Y.  
[http://9cays.com/](http://9cays.com/)
