0
我拉小時數據,緩存它,然後在javascript滾動條中使用該數據。無論如何。這是主要問題。我使用的是:在rails中的時區真的讓我感到困惑
config.time_zone = 'Eastern Time (US & Canada)'
好看起來很好,當我做:
Entry.first.created_at #datetime -0500
看起來不錯,但它不是當我使用以下範圍
scope :hourly, lambda {|h|
g = DateTime.current.beginning_of_day + h.hours
where(created_at: g..g+1.hours)
}
scope :hourly_by_date, lambda {|h,date|
g = DateTime.parse(date + " 00:00:00 Eastern Time (US & Canada)") + h.hours
where(created_at: g..g+1.hours)
}
scope :hours_ago, lambda {|h|
g = DateTime.current.beginning_of_hour - h.hours
where(created_at: g..g+1.hours)
}
它顯示的東西,說它是在午夜之前/之後創建的,當時我在下午6:06創建了該記錄(-0700) 這超出了沮喪,我可以使用一些指導。
謝謝。
請勿張貼生氣。它只是讓你看起來像一隻鵝:-) – paxdiablo
如果你改變'y.hours.since(x)'而不是'x + y.hours'(無論你有什麼'x + y.hours'),它會起作用嗎? AFAIK,'+'不會做時區,'#自''。我可能是錯的... – Amadan
問題不在於我的+時間不起作用,而是。但是當生成sql查詢時,與使用UTC的數據庫相比,它使用錯誤的日期/時間。 –