Why doesn’t `config.time_zone` seem to do anything?

Here’s a list of concepts and things that may help you:

config.time_zone doesn’t set “Server Time”, that is controlled by your operating system usually.

Rails always stores your dates in UTC in the database (unless you change a different setting).

Time.now returns the localtime for your computer in your timezone and it also includes the local timezone offset from your operating system, which means Ruby and therefore Rails knows how to convert localtime into UTC. You can try this by using irb directly, so no Rails libraries are loaded:

ctcherry$ irb
>> Time.now
=> Mon Feb 21 20:53:14 -0800 2011
>> 

If config.time_zone, or Time.zone is set, to lets say EST, Rails expects that if you set a datetime attribute that you mean for that time and date to be in specified timezone, in this case EST. This is why you set Time.zone equal to your end users timezone, so they can use their local time and dates, and you can pass them directly into your ActiveRecord models and Rails can convert it to UTC for storage in the database.

Does that help at all?

Leave a Comment