简体   繁体   English

Rails时区-本地主机和生产服务器之间的结果不同

[英]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 服务器: Tue 7 Apr 2015 11:04:53 MDT本地Tue 7 Apr 2015 11:04:53 MDTTue Apr 7 11:05:40 MDT 2015

Application.rb: 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 这两种环境显示@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. 不应使用Date.today ,因为它完全忽略了时区。 Always use Time.zone.today or Date.current instead. 始终改用Time.zone.todayDate.current

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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