Sunday, April 3, 2011

Ruby on Rails time zone

The following are all the timezones in Ruby on Rails 3  (as of Rails 3.0.5)

We can set it in config/application.rb, as

config.time_zone = 'Pacific Time (US & Canada)'

Note that it needs to be the exact string -- if we use:

config.time_zone = 'Pacific Time'      # NOT GOOD

it will stop the server from starting up.

The line Time.zone = 'Pacific Time (US & Canada)'   can change the time zone in view, but in the controller, the time zone will still be UTC.

The way to get all Time Zones in Rails is:


$ rake time:zones:all

* UTC -11:00 *
International Date Line West
Midway Island
Samoa

* UTC -10:00 *
Hawaii

* UTC -09:00 *
Alaska

* UTC -08:00 *
Pacific Time (US & Canada)
Tijuana

* UTC -07:00 *
Arizona
Chihuahua
Mazatlan
Mountain Time (US & Canada)

[...]


* UTC +00:00 *
Casablanca
Dublin
Edinburgh
Lisbon
London
Monrovia
UTC

[...]


* UTC +08:00 *
Beijing
Chongqing
Hong Kong
Irkutsk
Kuala Lumpur
Perth
Singapore
Taipei
Ulaan Bataar
Urumqi

[...]


No comments:

Post a Comment

Followers