获取基于数据的日期和时间

时间:2015-09-03 03:43:42

标签: ruby-on-rails ruby-on-rails-4 timezone

我试图从今天开始查找结果,但如果时间介于12:00am-5:00am

之间,我也想包括昨天的计划

现在我有以下

def self.current
    where(
      "plan_date >= :today",
      today: Date.current,
    )
end

有没有办法可以根据用户时区知道一天中的时间,这个时区在应用控制器中设置为低于标准,并确保如果它在6之前:第二天我想要包含前几天的结果同样。

def set_time_zone(&block)
    if current_user
      Time.use_zone(current_user.time_zone_name, &block)
    else
      yield
    end
end

1 个答案:

答案 0 :(得分:1)

试试这个:

<ul>
  <li>
    <div class="R" style="background-color:red;">Bat</div>
    <div class="R" style="background-color:green;">description</div>
  </li>
  <li>
    <div class="R" style="background-color:red;">Cat</div>
  </li>
  <li>
    <div class="R" style="background-color:green;">Rat</div>
    <ul>
      <li>
        <div class="R" style="background-color:red;">one
          <div class="R" style="background-color:green;">blah</div>
          <div class="R" style="background-color:red;">blah blah</div>
        </div>
      </li>
      <li>
        <div class="R" style="background-color:green;">two
          <div>
      </li>

    </ul>
  </li>
</ul>

...其中def self.current where( "plan_date >= :today", today: (Time.zone.now.in_time_zone(get_user_time_zone) - 6.hours).beginning_of_day, ) end 返回用户的时区(E.G。:get_user_time_zone)。我正在使用America/New_York,因为您希望它“在当地时间早上6点之前。”