0

I can't understand why Date.utc is making this difference:

Please not that the date is different:

1.9.3-p327 :009 > time = Date.parse("2013-07-04 15:39:45 -0700").to_time
 => 2013-07-04 00:00:00 +0300    

and:

1.9.3-p327 :010 > time = Date.parse("2013-07-04 15:39:45 -0700").to_time.utc
 => 2013-07-03 21:00:00 UTC 

UPDATE: Even if I provide the UTC within the date string, still 4th of July becomes 3rd.

1.9.3-p327 :017 > time = Date.parse("2013-07-04 1:00:00 UTC").to_time.utc
 => 2013-07-03 21:00:00 UTC 
1.9.3-p327 :018 > time = Date.parse("2013-07-04 21:00:00 UTC").to_time.utc
 => 2013-07-03 21:00:00 UTC 
1.9.3-p327 :019 > time = Date.parse("2013-07-04 23:00:00 UTC").to_time.utc
 => 2013-07-03 21:00:00 UTC 

My guess is this is because Date.parse doesn't accept an indication about UTC as a parameter. How would you make it work? Thanks.

4

1 回答 1

1

你能试试吗DateTime.parse("2013-07-04 1:00:00 UTC").to_time.utc

我有

irb(main):003:0>require 'date'
irb(main):005:0> DateTime.parse("2013-07-04 1:00:00 UTC").to_time.utc
=> 2013-07-04 01:00:00 UTC

谢谢

于 2013-08-12T12:10:24.130 回答