0
我可以執行以下操作並獲取正確時區中的TimeWithZone對象。使用ActiveSupport :: TimeWithZone指定UTC偏移量而不是時區ActiveSupport :: 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
&紅寶石2.4.1
正是我一直在尋找,謝謝。我很難在文檔中找到它,但卻發現了這樣的情況。超級有用。 – theartofbeing