Skip to content

Instantly share code, notes, and snippets.

@fabrizioc1
Last active December 15, 2015 20:09
Show Gist options
  • Save fabrizioc1/5316290 to your computer and use it in GitHub Desktop.
Save fabrizioc1/5316290 to your computer and use it in GitHub Desktop.
List time zones with UTC and DST offsets
new File("/tmp/java_timezones.txt").withWriter { out ->
TimeZone.getAvailableIDs().each{ timezoneId ->
timezone = TimeZone.getTimeZone(timezoneId)
def items = [timezone.getID(),
(int)(timezone.getRawOffset()/1000),
(int)(timezone.getDSTSavings()/1000)]
out.print sprintf("%6d %32s %6d\n",items[1],items[0],items[2])
}
}
require 'bundler/setup'
require 'active_support/time_with_zone'
File.open('/tmp/ruby_timezones.txt','w'){|out|
out.puts ActiveSupport::TimeZone.all.map{|t| t.tzinfo }.map{|tz|
sprintf("%6d %32s %6d",tz.current_period.utc_offset, tz.name, tz.current_period.std_offset)
}
}
offsets = TZInfo::Timezone.all.map{|tz| [tz.current_period.utc_offset/3600.0,tz.name] }.sort_by{|o| o[0] }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment