Devon Quick Devon Quick - 6 months ago 37
Ruby Question

timezone id to short timezone (pst, pdt, cst, etc)

I use Googles Timezone API to get TimeZoneID and I pass it to the ruby gem TZInfo to get the local time. How can I get the Timezones short name (PST, PDT, EST, etc...) from this info. I tried

but that returns 'UTC'. This is a ruby on rails app.


TZInfo::Timezone#strftime ought to work:

require "tzinfo"

tz = TZInfo::Timezone.get("America/New_York")
puts tz.strftime("%Z")

If you tried that and it didn't work, that's mysterious.

Alternatively, you can use TZInfo::TimezonePeriod#abbreviation:

tz = TZInfo::Timezone.get('America/New_York')
period = tz.period_for_utc(
puts period.abbreviation