【发布时间】:2018-01-26 09:23:24
【问题描述】:
Time.current 的文档说:
当设置了
Time.zone或config.time_zone时返回Time.zone.now, 否则只返回Time.now。# File activesupport/lib/active_support/core_ext/time/calculations.rb, line 36 def current ::Time.zone ? ::Time.zone.now : ::Time.now end
但是Time.zone 什么时候没有在 Rails 中设置?
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
# config.time_zone = 'Berlin'
我已经注释掉了config.time_zone,我仍然得到等于'UTC'的Time.zone,因为它显然在注释中提到了默认设置。那么,使用Time.current 而不是Time.zone.now 有什么意义呢?
PS:我在 Rails 4.1.16 上观察到这一点
【问题讨论】:
标签: ruby-on-rails time timezone