Search code examples
rubydateutc

ruby date gem utc offset


I have a unix time string "1420960690" in GMT. I could convert it to readable text by using the ruby "date" gem like so:

require 'date'
DateTime.strptime("1420960690", '%s')
# => #<DateTime: 2015-01-11T07:18:10+00:00 ((2457034j,26290s,0n),+0s,2299161j)>

The date is displayed in GMT, and I need MST. I don't understand the offset for UTC in the documentation. http://ruby-doc.org/core-2.2.0/Time.html Example or a link in the right direction would be appreciated.

The output im looking for is 2015-01-10T00:18:10+00:00 I'm just not sure how to get to that answer without using another gem.


Solution

  • Obviously the offset for UTC (and usually GMT) is 0. That is what UTC is for.