Flowdock

Notes posted by stadiv

RSS feed
July 8, 2010 - (>= v2.1.0)
1 thank

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.

http://tzinfo.rubyforge.org/

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)
  end
end

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