Reputation: 2662
Got into a really sticky situation, while saving a model instance I get a value of created_at dated 9 hours ago.
While executing DateTime.now I get exactly the NOW time, as well as when I execute NOW() and current_timestamp on SQL server.
So my question would be:
Any help would be appreciated
Upvotes: 1
Views: 1903
Reputation: 11421
http://www.ruby-doc.org/core-2.0.0/Time.html#method-c-now
Time.now
- Returns a Time object initialized to the current system time.
created_at
- is saved the GMT time, in my case it shows 10.00 for example but my system time is 12.00 as I am 2 hours ahead of GMT.
Set the TimeZone in environment.rb
:
# config/environment.rb
config.time_zone = "Central Time (US & Canada)"
Run rake time:zones:all
to get the actual listing and use the one you need, like Central Time (US & Canada)
.
Upvotes: 2