时区的日期范围

时间:2011-08-08 14:50:37

标签: ruby-on-rails

application.rb中

config.time_zone = 'Athens'

我想列出在任何日期范围之间发布的条目。下面的查询开始列出在03:00之后发布的条目而不是00:00任何帮助将不胜感激。

@from_date = (Time.zone.now-1.day).to_date.to_datetime #iam trying to set time to 00:00
@to_date = (Time.zone.now+1.day).to_date.to_datetime
Entry.where(:spam => false, :published_at => @report_from_date..@report_to_date)

1 个答案:

答案 0 :(得分:1)

您可以查看使用beginning_of_dayend_of_day。例如,要显示当天的所有内容:

@from_date = Time.zone.now.beginning_of_day # Returns 2011-08-08 00:00:00
@to_date = Time.zone.now.end_of_day # Returns 2011-08-08 23:59:59