Skip to content

Instantly share code, notes, and snippets.

@queso
Created September 22, 2008 15:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save queso/12015 to your computer and use it in GitHub Desktop.
Save queso/12015 to your computer and use it in GitHub Desktop.
Time.now doesn't work for automatic timezone support, but it seems Time.zone.now does. All the documentation indicates that Time.now should work as well...
## Anyone care to explain why using Time.now and Time.zone.now result in two different times in the db?
>> e = Event.create(:title => "Test2", :url => "http://tests.com", :length => 60, :starts_at => Time.now + 1.day)
=> #<Event id: 4, user_id: nil, title: "Test2", url: "http://tests.com", starts_at: "2008-09-23 16:05:14", length: 60, category_id: nil, format_id: nil, advertisment_type: nil, highlight_type: nil, created_at: "2008-09-22 20:05:14", updated_at: "2008-09-22 20:05:14", permalink: "test2", description: nil, popularity: 0.0, promoted: false>
>> Time.now + 1.day
=> Tue Sep 23 16:05:26 -0400 2008
>> e = Event.create(:title => "Test2", :url => "http://tests.com", :length => 60, :starts_at => Time.zone.now + 1.day)
=> #<Event id: 5, user_id: nil, title: "Test2", url: "http://tests.com", starts_at: "2008-09-23 20:05:43", length: 60, category_id: nil, format_id: nil, advertisment_type: nil, highlight_type: nil, created_at: "2008-09-22 20:05:43", updated_at: "2008-09-22 20:05:43", permalink: "test2-2", description: nil, popularity: 0.0, promoted: false>
>> Time.zone.now + 1.day
=> Tue, 23 Sep 2008 15:06:04 CDT -05:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment