I can use Time.parse to parse a timestamp in the local timezone, e.g.:
irb(main):001:0> require 'time'
=> true
irb(main):002:0> t = Time.parse('20050103-14:31:26')
=> Mon Jan 03 14:31:26 EST 2005
But how can I parse the above timestamp in a timezone other than the
local timezone (e.g. I want the method to assume that the timestamp is
in UTC)?
Paul
Paul Brannan wrote:
I can use Time.parse to parse a timestamp in the local timezone, e.g.:
irb(main):001:0> require 'time'
=> true
irb(main):002:0> t = Time.parse('20050103-14:31:26')
=> Mon Jan 03 14:31:26 EST 2005
But how can I parse the above timestamp in a timezone other than the
local timezone (e.g. I want the method to assume that the timestamp is
in UTC)?
ENV['TZ'] = 'UTC'
or even easier, append a Z to the string:
$ irb
irb(main):001:0> require 'time'
=> true
irb(main):002:0> Time.parse('20050103-14:31:26')
=> Mon Jan 03 14:31:26 PST 2005
irb(main):003:0> Time.parse('20050103-14:31:26Z')
=> Mon Jan 03 14:31:26 UTC 2005
Steve
Or just the full timezone name (appending "UTC", "EDT", "PST" will all
have the expected effect).
Cheers,
Navin.
ยทยทยท
Steven Jenkins <steven.jenkins@ieee.org> wrote:
or even easier, append a Z to the string: