1
節省一個區域的時間並在另一個區域查看它們的標準是什麼?我有這個在我的environment.rb
:以UTC保存日期時間,在Rails中查看/查詢用戶的時區?
config.time_zone = 'UTC'
但我想渲染它,然後進行查詢,如在他們的時區,在那裏beginning_of_day
返回當日開始在他們的時區而不是UTC「今天創建的所有帖子」。 rails是否已經在後臺處理轉換?
這裏的問題:
@now = Time.now
=> Wed Jan 26 09:50:04 -0600 2011
User.count(:conditions => ["created_at > ?", @now])
SQL (1.3ms) SELECT count(*) AS count_all FROM `users` WHERE (created_at > '2011-01-26 09:50:04')
=> 1
@now = Time.now.utc
=> Wed Jan 26 15:50:10 UTC 2011
User.count(:conditions => ["created_at > ?", @now])
SQL (1.2ms) SELECT count(*) AS count_all FROM `users` WHERE (created_at > '2011-01-26 15:50:10')
=> 0