简体   繁体   中英

Rails timezone - different results between localhost and production server

I've got a search for records by Date, and the results vary by a day between my localhost and the server.

Both have the same date:

Server: Tue 7 Apr 2015 11:04:53 MDT Localhost: Tue Apr 7 11:05:40 MDT 2015

Application.rb:

    config.time_zone = 'Mountain Time (US & Canada)'
    config.active_record.default_timezone = 'Mountain Time (US & Canada)'

Query:

@beginning_of_week = Date.today.beginning_of_week
@behind = Section.where(trade_id: current_user.trade_id).
                        where("DATE(date) < ?", @beginning_of_week).
                        where("complete = false").
                        count

Both environments show the same date for @beginning_of_week - 2015-04-06

Any ideas how I can further trouble shoot this?

Date.today should not be used, because it completely ignores time zones. Always use Time.zone.today or Date.current instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM