In Ruby 1.9.2 we can do:
Time.new(2008,6,21, 13,30,0, "+09:00")
How to do the same in R开发者_如何学运维uby 1.8.7?
Depending on your needs, you can use Time.utc, Time.gm (a synonym for Time.utc), or Time.local. All three take arguments to set specific time and date.
http://www.ruby-doc.org/core-1.8.7/classes/Time.html
If I understand the question correctly, you are trying to set the time zone of a time by passing it the +09:00 offset. In Ruby 1.8.7, the only time zones you can use are your local (system) time, or UTC/GMT.
What you can do is create a new time, equivalent to the time you desire, but in UTC instead of UTC+9:
ruby-1.8.7-p302 :052 > Time.parse("2008-06-21 13:30:00 UTC") - 9*3600
=> Sat Jun 21 04:30:00 UTC 2008
Which is the same time as:
ruby-1.9.2-p0 :003 > Time.new(2008,6,21, 13,30,0, "+09:00").utc
=> 2008-06-21 04:30:00 UTC
精彩评论