Reputation: 166
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.
Upvotes: 1
Views: 101
Reputation: 166
I ended up using.
DateTime.strptime("1420960690", '%s').to_time.utc - 25200
=> 2015-01-11 00:18:10 UTC
I got the off set by looking up MST from GMT which was 7 hours, so (7 * 60min) = 420min * 60sec = 25200 total seconds for the offset.
Upvotes: 1
Reputation: 168101
Obviously the offset for UTC (and usually GMT) is 0. That is what UTC is for.
Upvotes: 2