Rails 时区 - 本地主机和生产服务器之间的不同结果
Rails timezone - different results between localhost and production server
我按日期搜索了记录,结果在我的本地主机和服务器之间一天有所不同。
两者的日期相同:
服务器:Tue 7 Apr 2015 11:04:53 MDT
本地主机: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)'
查询:
@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
两个环境显示@beginning_of_week - 2015-04-06
的相同日期
有什么办法可以解决这个问题吗?
Date.today
不应使用,因为它完全忽略了时区。始终使用 Time.zone.today
或 Date.current
。
我按日期搜索了记录,结果在我的本地主机和服务器之间一天有所不同。
两者的日期相同:
服务器:Tue 7 Apr 2015 11:04:53 MDT
本地主机: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)'
查询:
@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
两个环境显示@beginning_of_week - 2015-04-06
有什么办法可以解决这个问题吗?
Date.today
不应使用,因为它完全忽略了时区。始终使用 Time.zone.today
或 Date.current
。