# Quick Tip: Rails 2.1 Time Zones

> Setting your application time zone in Rails 2.1 with config.time_zone

- Author: Curtis Miller
- Published: 2008-09-13
- Categories: rails, how-to
- Canonical URL: https://millarian.com/posts/quick-tip-rails-2-1-time-zones/

My last quick tip involved setting your time zone in Ubuntu Hardy (dead link: https://millarian.com/ops/quick-tip-setting-timezone-on-ubuntu-hardy), so now, how do you set your time zone in a Ruby on Rails application? Rails 2.1 makes it much easier to manage time zone settings than it was previously.

Add the following to your environment configuration file:

## config/environment.rb

```
config.time_zone = 'Arizona'
```

Replace Arizona with your own time zone. You can find a list of valid values by running any of the following rake tasks:

```
rake time:zones:all
rake time:zones:local
rake time:zones:us
```

Your data will still be stored in UTC time, but it will be converted into the specified time zone when it is type cast on retrieval.

**Update:** If you set both your server's time zone and your applications time zone then you may see some incorrect times. I believe this is because you'll be storing local times and the Rails app will be trying to convert them to local - a double conversion. So be careful.

## References

- [What's New in Edge Rails: Easier Timezones](http://ryandaigle.com/articles/2008/1/25/what-s-new-in-edge-rails-easier-timezones)
- [Rails 2.1 Time Zone Support: An Overview](http://mad.ly/2008/04/09/rails-21-time-zone-support-an-overview/)
- [Updating MySQL DATETIMEs for Rails 2.1 Time Zones](http://metautonomo.us/2008/06/02/updating-mysql-datetimes-for-rails-21-time-zones/)
