Ruby on Rails
HowtoSetDefaultTimeZone (Version #9)

ActiveRecord Timestamps

As of ActiveRecord 1.4.0 (January 4th, 2005) Base.default_timezone determines whether to use Time.local (using :local) or Time.utc (using :utc) when pulling dates and times from the database. This is set to :local by default.

Set default to UTC

ActiveRecord::Base.default_timezone = :utc

Local Time Zone

Whether you need to change the local time zone for your entire web app or just temporarily, one way to do so is by setting the ENV['TZ'] variable, as such:

ENV['TZ'] = 'US/Eastern'

The list of time zones is typically in your /usr/share/zoneinfo directory. This solution, and particularly what values to use, are likely operating system specific. You can put this code anywhere. If you wish to change it for your entire web app, it is recommended to put it at the bottom of your config/environment.rb file.

Be aware that setting the ENV['TZ'] variable on a Windows system has no effect.

More Resources

ActiveRecord Timestamps

As of ActiveRecord 1.4.0 (January 4th, 2005) Base.default_timezone determines whether to use Time.local (using :local) or Time.utc (using :utc) when pulling dates and times from the database. This is set to :local by default.

Set default to UTC

ActiveRecord::Base.default_timezone = :utc

Local Time Zone

Whether you need to change the local time zone for your entire web app or just temporarily, one way to do so is by setting the ENV['TZ'] variable, as such:

ENV['TZ'] = 'US/Eastern'

The list of time zones is typically in your /usr/share/zoneinfo directory. This solution, and particularly what values to use, are likely operating system specific. You can put this code anywhere. If you wish to change it for your entire web app, it is recommended to put it at the bottom of your config/environment.rb file.

Be aware that setting the ENV['TZ'] variable on a Windows system has no effect.

More Resources