ruby - Parse time with strptime using Time.zone -
i trying parse datetime time class in ruby 2.0. can't figure out how parse date , in specified timezone. have used time.zone.parse
parse date first call time.zone
, set specified timezone. in below example, set zone not effect strptime
, have tried doing time.zone.parse(date)
can't parse date 1 below.
time.zone = "central time (us & canada)" #=> "central time (us & canada)" irb(main):086:0> time.strptime("08/26/2013 03:30 pm","%m/%d/%y %i:%m %p") #=> 2013-08-26 15:30:00 -0400
time.zone
isn’t part of ruby, it’s part of activesupport (which included rails). such, strptime
not know time.zone
@ all. can, however, convert normal ruby time activesupport::timewithzone using in_time_zone
, uses time.zone
’s value default:
require 'active_support/core_ext/time' time.zone = 'central time (us & canada)' time = time.strptime('08/26/2013 03:30 pm', '%m/%d/%y %i:%m %p') #=> 2013-08-26 15:30:00 -0400 time.in_time_zone #=> mon, 26 aug 2013 14:30:00 cdt -05:00
Comments
Post a Comment