Weird created_at behavior
-
06-07-2019 - |
Question
I've set config.time_zone = 'UTC'
in environment.rb
, and yet still I get some weird behavior with Rails' built-in datetime fields:
>> Time.now
=> Sun Jun 21 17:05:59 -0700 2009
>> Feedback.create(:body => "testing")
=> #<Feedback id: 23, body: "testing", email_address: nil, name: nil, created_at: "2009-06-22 00:06:09", updated_at: "2009-06-22 00:06:09">
>> Time.parse(Feedback.last.created_at.to_s)
=> Mon Jun 22 00:06:09 UTC 2009
Any thoughts?
Solution
It looks like it's properly setting the timezone in the ActiveRecord object, so I don't think you need to worry too much. If you want to force your timestamp from Rails to use UTC, you can use Time.utc
.
Time.now.utc
=> Mon Jun 22 00:54:21 UTC 2009
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow