我已在/config/application.rb
_ DateTime
_ 我怎样才能让它在我的应用程序的时区?.new
GMT
/config/application.rb
config.time_zone = 'Pacific Time (US & Canada)'
irb
irb> DateTime.now
=> Wed, 11 Jul 2012 19:04:56 -0700
irb> mydate = DateTime.new(2012, 07, 11, 20, 10, 0)
=> Wed, 11 Jul 2012 20:10:00 +0000 # GMT, but I want PDT
使用in_time_zone
不起作用,因为这只是将 GMT 时间转换为 PDT 时间,这是错误的时间:
irb> mydate.in_time_zone('Pacific Time (US & Canada)')
=> Wed, 11 Jul 2012 13:10:00 PDT -07:00 # wrong time (I want 20:10)