Convert DateTime String to UTC in rails

Time.parse("2010-01-01 12:30:00").getutc

EDIT

(grinding teeth while thinking about the nightmare which is Ruby/Rails date/time handling)

OK, how about this:

Time.zone.parse("2010-01-01 12:30:00").utc

Note that Time.zone.parse returns a DateTime, while appending the .utc gives you a Time. There are differences, so beware.

Also, Time.zone is part of Rails (ActiveSupport), not Ruby. Just so you know.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)