Skip to Content
Ruby on Rails® for Microsoft Developers
book

Ruby on Rails® for Microsoft Developers

by Antonio Cangiano
April 2009
Intermediate to advanced content levelIntermediate to advanced
479 pages
12h 55m
English
Wrox
Content preview from Ruby on Rails® for Microsoft Developers

5.10. Setting a Default Time Zone

Every time a model's datetime attribute is saved in the database, this becomes stored as a UTC time. The problem is that the dates and times presented to the visitor and the blog author are UTC times, rather than a predefined local time zone. When you click New Article you'll see that the default date and time selected are based on UTC, not the local time zone. This implies that if you want to schedule a post in the future for a certain "local time," you'll have to offset it (in your head) to obtain the UTC time. Likewise, having chosen the "long ordinal" presentation of the date and time, when showing an article the readers of your blog will just see an absolute numeric representation of the time and won't assume that it's a UTC time.

Figure 5.16. Figure 5-16

Depending on your application's requirements, this may or may not be a big deal. Luckily for you, Rails 2.2.2 provides excellent support for time zones and setting a predefined time zone for your application is extremely easy. I live in Toronto, so my time zone is Eastern Time (US & Canada). You can see a list of local time zones by running the rake task time:zones:local:

C:\projects\blog> rake time:zones:local
(in C:/projects/blog)

* UTC −05:00 *
Bogota
Eastern Time (US & Canada)
Indiana (East)
Lima
Quito

You can use rake time:zones:us to obtain only the US time zones matching the local ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Ruby on Rails™ 3 Tutorial: Learn Rails™ by Example

Ruby on Rails™ 3 Tutorial: Learn Rails™ by Example

Michael Hartl

Publisher Resources

ISBN: 9780470374955Purchase book