en3fea
Last Updated: February 25, 2016
·
2.247K
· sheerun
Photo on 08.01.2013 at 04.15

Parse Time in given TimeZone

ActiveSupport::TimeZone["America/New_York"].
  parse("2012-06-29 12:20")
=> Fri, 29 Jun 2012 12:20:00 EDT -04:00

You can also get current time in other time zone:

ActiveSupport::TimeZone["America/New_York"].now
=> Thu, 04 Oct 2012 08:02:45 EDT -04:00

See also:

1 Response
Add your response

5847
09809b573afd2ad5e84d368796fd24b1

In Rails app I find it useful to do:
Time.zone.parse("2012-06-29 12:20")

Not doing it can lead to serious bugs:
[1] pry(main)> Time.zone.parse("2012-06-29 12:20")
=> Fri, 29 Jun 2012 12:20:00 IST +01:00
[2] pry(main)> Time.parse("2012-06-29 12:20")
=> 2012-06-29 12:20:00 +0000

over 1 year ago ·