Monday, June 18, 2012

Time zones in Rails

Don't use Date.today or Date.yesterday if you set config.time_zone / you do things similar to this post or this time zones railscast.

These two functions of Date don't mix well with Rails' time zone setting features.

Instead, use Time.now.in_time_zone to get the time in the right time zone you specified or Time.now.in_time_zone.to_date for the date.

Time.now just gets the time of the place where the server is running.

Basically, get a time object and convert as appropriate.

No comments:

Post a Comment

Please be considerate in what you say.