的文档Time.current
说:为什么使用Time.current超过Time.zone.now Rails中,当Time.zone总是设置?
返回
Time.zone.now
时Time.zone
或config.time_zone
设置, 否则直接返回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
和我仍然得到Time.zone等于“UTC”,因为它显然是设置在默认情况下的注解中提到的。那么,使用Time.current
而不是Time.zone.now
有什么意义?
PS:我on Rails的4.1.16