Method: ActiveSupport::TimeZone#strptime
- Defined in:
- activesupport/lib/active_support/values/time_zone.rb
#strptime(str, format, now = now()) ⇒ Object
Parses str
according to format
and returns an ActiveSupport::TimeWithZone.
Assumes that str
is a time in the time zone self
, unless format
includes an explicit time zone. (This is the same behavior as parse
.) In either case, the returned TimeWithZone has the timezone of self
.
Time.zone = 'Hawaii' # => "Hawaii"
Time.zone.strptime('1999-12-31 14:00:00', '%Y-%m-%d %H:%M:%S') # => Fri, 31 Dec 1999 14:00:00 HST -10:00
If upper components are missing from the string, they are supplied from TimeZone#now:
Time.zone.now # => Fri, 31 Dec 1999 14:00:00 HST -10:00
Time.zone.strptime('22:30:00', '%H:%M:%S') # => Fri, 31 Dec 1999 22:30:00 HST -10:00
However, if the date component is not provided, but any other upper components are supplied, then the day of the month defaults to 1:
Time.zone.strptime('Mar 2000', '%b %Y') # => Wed, 01 Mar 2000 00:00:00 HST -10:00
498 499 500 |
# File 'activesupport/lib/active_support/values/time_zone.rb', line 498 def strptime(str, format, now = now()) parts_to_time(DateTime._strptime(str, format), now) end |