Rails: How to parse date-time string into a specific time zone
Try this:
zone = "Central Time (US & Canada)" ActiveSupport::TimeZone[zone].parse("2013-04-03 17:47:00")
Use String#in_time_zone
(Rails 4+)
I personally prefer using String#in_time_zone
:
>> '22.09.1986 10:30'.in_time_zone('Central Time (US & Canada)')# => Mon, 22 Sep 1986 10:30:00 CDT -05:00
This parses the date and time in the String into the time zone provided.
%Z
is the correct way to specify a Time zone name. Have you tried the following ?
date_and_time = '%m-%d-%Y %H:%M:%S %Z'DateTime.strptime("04-15-2010 10:00:00 Central Time (US & Canada)",date_and_time)