Does anyone know why Time.parse
seems to misinterpret the offset??
# Correct:
ruby-1.9.2-p136 > DateTime.parse "2011-04-07T13:53:00-3"
=> Thu, 07 Apr 2011 13:53:00 -0300
ruby-1.9.2-p136 > Time.parse "2011-04-07T13:53:00-3"
=> 2011-04-07 13:53:00 +0300
The format doesn't seem to make any difference:
ruby-1.9.2-p136 :027 > Time.parse "2011-04-07T13:53:00-0300"
=> 2011-04-07 19:53:00 +0300
ruby-1.9.2-p136 :028 > Time.parse "2011-04-07T13:53:00-03"
=> 2011-04-07 19:53:00 +0300
ruby-1.9.2-p136 :029 > Time.parse "2011-04-07T13:53:0开发者_Go百科0-03:00"
=> 2011-04-07 19:53:00 +0300
I think Time.parse converts it into your timezone. So when you are in +3 and you give it a time of 13.53:00-3, it will be 19.53:00+3 local time for you.
Also if you look at the Ruby Doc you will see that the Time#parse method only understands the timezone abbreviations described in RFC 822 and the system timezone.
So you should use "-0300" instead of "-3".
精彩评论