的文檔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