Last active
June 14, 2020 04:19
-
-
Save navjeetc/f687cb0f36339c0316001d025b77aa29 to your computer and use it in GitHub Desktop.
Convert time from one time zone to another
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Converts time selectec time zone to time in Sydney Australia nad New Delhi in Rails | |
time_zones = ActiveSupport::TimeZone.all.map(&:name) | |
time_from = '2020-06-20 23:00:00' | |
Time.zone = time_zones.first #'America/New_York' | |
time_zones_to_convert_to = ["Australia/Sydney", "New Delhi"] | |
from_time = Time.zone.parse(time_from) | |
puts "From #{Time.zone} #{from_time}" | |
time_zones_to_convert_to.each do|to_zone| | |
puts "#{to_zone} #{from_time.in_time_zone(to_zone)}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment