I'm parsing something like this:
11/23/10 23:29:57
which has no time zone associated with it, but I know it's in the UTC time zone (while I'm not). How can I get Ruby to parse this as if it were in the UTC timezone?
I'm parsing something like this:
11/23/10 23:29:57
which has no time zone associated with it, but I know it's in the UTC time zone (while I'm not). How can I get Ruby to parse this as if it were in the UTC timezone?
If your using rails you can use the
ActiveSupport::TimeZone
helpersIt is designed to have the timezone set at the beginning of the request based on user timezone.
Everything does need to have
Time.zone
on it, soTime.parse
would still parse as the servers timezone.http://api.rubyonrails.org/classes/ActiveSupport/TimeZone.html
Note: the time format you have above was no longer working, so I changed to a format that is supported.
You could just append the UTC timezone name to the string before parsing it:
If you are using ActiveSupport [from Rails, e.g], you can do this:
An aliter to @Pete Brumm's answer without Time.zone set/unset