【发布时间】:2017-10-19 16:52:11
【问题描述】:
借助 ActiveSupport::TimeWithZone,我可以执行以下操作并在正确的时区取回 TimeWithZone 对象。
Time.current.in_time_zone('Alaska')
:> Thu, 19 Oct 2017 08:45:08 AKDT -08:00
是否有与 in_time_zone 等效的方法,我可以在几秒钟内将 UTC 偏移量传递给它,并返回具有指定偏移量的 TimeWithZone 对象?
offset = -25200 # -25200 seconds == -08:00
Time.current.in_utc_offset(offset)
:> Thu, 19 Oct 2017 08:45:08 -08:00
提前致谢!
使用 Rails 5.1.2 和 Ruby 2.4.1
【问题讨论】:
标签: ruby-on-rails ruby activesupport