I am fairly new to ruby. I have a date value say "2014-12-15T19:56:59Z" and an offset value say "-06:00". How can I convert the given date time in the timezone given by offset value.
Asked
Active
Viewed 233 times
-3
-
https://api.rubyonrails.org/classes/ActiveSupport/TimeZone.html – Kielstra Jan 07 '21 at 16:24
-
https://ruby-doc.org/core-2.7.2/Time.html#method-i-getlocal – engineersmnky Jan 07 '21 at 16:29
-
BTW, −06:00 is an _offset_ and multiple time zones can have this offset during the year. – Stefan Jan 07 '21 at 16:50
1 Answers
2
Using Time::parse
and Time#localtime
:
require 'time'
t = Time.parse('2014-12-15T19:56:59Z')
#=> 2014-12-15 19:56:59 UTC
t.localtime('-06:00')
#=> 2014-12-15 13:56:59 -0600

Stefan
- 109,145
- 14
- 143
- 218