Reputation: 2735
In the rails application by default created_at and updated_at filed are stored in UTC format. i want to store created_at and updated_at field in my local timezone i.e in "Chennai" Timezone.
I wrote below to lines in my application.rb file but still my created_at and updated_at fields dates are saved in UTC timezone and not in my local timezone.
config.time_zone = 'Chennai'
config.active_record.default_timezone = :local
Please let me know what wrong i am doing here??
Thanks,
Sanjay Salunkhe
Upvotes: 2
Views: 200
Reputation: 3656
To make this happen you need to just add this to your application.rb
config.time_zone = 'Chennai'
config.active_record.default_timezone = :local
How to change default timezone for Active Record in Rails?
Also one optional but very important thing that you should also do is to set the default time of the server or servers( where your rails application is hosted ) to the timezone you are giving in application.rb
( in your case which is 'Chennai'
). For example this is how you can set timezone of an Ubuntu
server.
Its is very important that your server timezone and the default timezone in application.rb
are same to avoid unnecessary timezone related issues.
Upvotes: 2