v2.0.3 - Show latest stable - 1 note - Superclass: Object

A value object representing a time zone. A time zone is simply a named offset (in seconds) from GMT. Note that two time zone objects are only equivalent if they have both the same offset, and the same name.

A TimeZone instance may be used to convert a Time value to the corresponding time zone.

The class also includes #all, which returns a list of all TimeZone objects.


US_ZONES = /US|Arizona|Indiana|Hawaii|Alaska/ unless defined?(US_ZONES)


[R] name
[R] utc_offset
Show files where this class is defined (1 file)
Register or log in to add new notes.
July 8, 2010 - (>= v2.1.0)
0 thanks

Rails v2.1.0 has built-in time-zone support

Rails versions as of 2.1.0 have basic timezone support built-in to the Time object. However, to get a list of all the timezones you need to install the tzinfo gem.


All contries, all timezones:

TZInfo::Country.all.sort_by { |c| c.name }.each do |c|
  puts c.name # E.g. Norway
  c.zones.each do |z|
    puts "\t#{z.friendly_identifier(true)} (#{z.identifier})" # E.g. Oslo (Europe/Oslo)

TZInfo::TimeZone.get(identifier) returns a TimeZone -object by the identifier.