Devon Quick Devon Quick - 1 year ago 129
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.

Answer Source

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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download