Skip to content

Instantly share code, notes, and snippets.

@navjeetc
Last active June 14, 2020 04:19
Show Gist options
  • Save navjeetc/f687cb0f36339c0316001d025b77aa29 to your computer and use it in GitHub Desktop.
Save navjeetc/f687cb0f36339c0316001d025b77aa29 to your computer and use it in GitHub Desktop.
Convert time from one time zone to another
# 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