Time.new时区与system或config.time_zone不同?

时间:2014-12-10 18:15:20

标签: ruby-on-rails timezone

正如标题所示,我不知道发生了什么。我系统的时区是CST。在Rails的application.rb文件中,我将time_zone设置为CST(-6):

# 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 = 'Central Time (US & Canada)'

但请查看这一串命令......非常自我解释。第三行(Time.new)显示为-5偏移(又称东部时间)?但是,调用utc_offset表示它是-6偏移(中央,这是正确的)?如此迷茫。帮助

2.1.0 :001 > Time.now
 => 2014-12-10 12:10:32 -0600 
2.1.0 :002 > Time.zone.now
 => Wed, 10 Dec 2014 12:10:37 CST -06:00 
2.1.0 :003 > Time.new(2011, 3, 20)
 => 2011-03-20 00:00:00 -0500 
2.1.0 :004 > Time.new(2011, 3, 20).utc_offset
 => -18000 

1 个答案:

答案 0 :(得分:1)

这可能会导致夏令时。如果你看看你正在使用的日期,你会看到另一个:

2.1.0 :003 > Time.new(2011, 3, 20)

是3月的第三周,DLS发生在3月的第二个星期日(http://www.webexhibits.org/daylightsaving/b.html)。

相关问题