Ruby: Convert a time string to your local time zone

Posted Over 12 years ago. Visible to the public.

If you have a time given in a different time zone than your local one, parsing will convert it for you:

>> Time.parse('September 2nd, 3pm PST')
=> 2011-09-03 01:00:00 +0200

Note that in pure Ruby you need to require "tzinfo" (Ruby 1.9) or require "time" (Ruby 1.8) for Time.parse to be available.

Arne Hartherz
Last edit
Almost 12 years ago
Keywords
date
License
Source code in this card is licensed under the MIT License.
Posted by Arne Hartherz to makandra dev (2011-08-31 09:45)