How to get correct time zone offset in Rails 2.3?
-
25-05-2021 - |
Question
Using Rails 2.3, when I run ActiveSupport::TimeZone.us_zones
, I get the following:
....
* UTC -08:00 *
Pacific Time (US & Canada)
....
Now, since DST is in effect right now, the UTC offset should have been -07:00
!
Anyone know how to get the correct Time zone offsets in Rails 2.3 ?
Solution
You can use the UTC offset of the current time in that time zone:
zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)']
zone.now.utc_offset
=> -14400
zone.utc_offset
=> -18000
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow