Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a list of timezones in ruby?

Tags:

I would like to know, how to get a list of timezones in Ruby 2.0?

like image 292
user3613750 Avatar asked May 07 '14 20:05

user3613750


People also ask

How do you get the time zone in Ruby?

Ruby | Time zone() functionTime#zone() : zone() is a Time class method which returns the name of the time zone used for time like “UTC”, “GMT”.

How do I find time zones in rails?

In Rails, to see all the available time zones, run: $ rake time:zones:all * UTC -11:00 * American Samoa International Date Line West Midway Island Samoa * UTC -10:00 * Hawaii * UTC -09:00 * Alaska ... The default time zone in Rails is UTC.

How do I install Tzinfo?

Installation. The TZInfo gem can be installed by running gem install tzinfo or by adding gem 'tzinfo' to your Gemfile and running bundle install . To use the Ruby modules as the data source, TZInfo::Data will also need to be installed by running gem install tzinfo-data or by adding gem 'tzinfo-data' to your Gemfile .


2 Answers

with rails a simple way is:

ActiveSupport::TimeZone.all 
like image 57
ipegasus Avatar answered Oct 12 '22 09:10

ipegasus


If you want a ruby only solution, (rails independent) you can use the tzinfo gem.

require 'tzinfo'  TZInfo::Timezone.all_country_zone_identifiers TZInfo::Timezone.all_country_zones #... #America/Chicago #America/Indiana/Tell_City #America/Indiana/Knox #America/Menominee #America/North_Dakota/Center #America/North_Dakota/New_Salem #America/North_Dakota/Beulah #America/Denver #America/Boise #... 
like image 45
xlembouras Avatar answered Oct 12 '22 07:10

xlembouras