0

I have been working with one rails project, when the creation of object , i need exact time with created_at field.I have tried these in applicaiton.rb

config.time_zone = 'Chennai'
config.active_record.default_timezone = :local

and when i tried in console, it shows like

Time.now
=> 2014-08-28 21:31:31 +0530
m.created_at
=> Thu, 28 Aug 2014 21:28:26 IST +05:30

but the problem is when i take one database object, the created_at time is

 created_at: "2014-08-28 15:58:26"
amtest
  • 690
  • 1
  • 6
  • 26

1 Answers1

1

Rails stores all timestamps in UTC in the database. When you type those commands on console it converts the timestamp to your specific timezone.

http://api.rubyonrails.org/classes/ActiveRecord/Timestamp.html

I your particular case 2014-08-28 15:58:26 UTC is same as 2014-08-28 21:28:26 IST.

Saving all timestamps as UTC makes the data consistent, and has less scope for ambiguity. You can then do all the conversions based on the timezone of your choice.

amit_saxena
  • 7,450
  • 5
  • 49
  • 64