Skip to content

Instantly share code, notes, and snippets.

@teeparham
Created May 5, 2011 23:22
Show Gist options
  • Save teeparham/958179 to your computer and use it in GitHub Desktop.
Save teeparham/958179 to your computer and use it in GitHub Desktop.
activesupport to_time
Loading development environment (Rails 3.0.7)
ruby-1.9.2-p180 :001 > s = Time.now.to_s
=> "2011-05-05 17:11:19 -0600"
ruby-1.9.2-p180 :002 > s.to_time
=> 2011-05-05 17:11:19 UTC <----- wrong
ruby-1.9.2-p180 :003 > s.to_time :local
=> 2011-05-05 17:11:19 -0600 <----- better, sort of
ruby-1.9.2-p180 :004 > Time.parse s
=> 2011-05-05 17:11:19 -0600 <----- plain ruby wins
# see https://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/string/conversions.rb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment