AnApprentice
AnApprentice

Reputation: 110950

Rails date and time is off on my local machine in created_at

ok this is very strange.

My computers clock is correct, but whenever I output a created_at field in the database and format it, the day/time are off my several hours...

Is there some Rails 3 localhost type setting?

Upvotes: 1

Views: 446

Answers (2)

Dave Pirotte
Dave Pirotte

Reputation: 3816

Rails 3 stores timestamps as UTC in the database. When you pull it out it will format according to config.time_zone in your config/application.rb.

ree-1.8.7-2010.02 > Thing.create
 => #<Thing id: 1, name: nil, created_at: "2010-10-10 17:57:47", updated_at: "2010-10-10 17:57:47"> 
ree-1.8.7-2010.02 > Thing.first.created_at
 => Sun, 10 Oct 2010 13:57:47 EDT -04:00 

Note the difference between created_at in the db and how it is displayed.

Upvotes: 3

Yannis
Yannis

Reputation: 5426

How is your config.time_zone configured? You can set it to the right timezone in application.rb (Rails3) or environment.rb (Rails") (check http://mad.ly/2008/04/09/rails-21-time-zone-support-an-overview/).

Upvotes: 2

Related Questions