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
    Can you please try DateTime.parse("2013-07-04 1:00:00 UTC").to_time Aug 12, 2013 at 12:08
  • DateTime.parse("2013-07-04 1:00:00 UTC").to_time => 2013-07-04 04:00:00 +0300
    – valk
    Aug 12, 2013 at 12:10
  • Please see my comments DateTime.parse("2013-07-04 1:00:00 UTC").to_time.utc Aug 12, 2013 at 12:11
  • That's the answer, please add it :) So is Date is parsing dates, and DateTime includes also the time. This explains. Thanks.
    – valk
    Aug 12, 2013 at 12:13

1 Answer 1

1

Can you please try DateTime.parse("2013-07-04 1:00:00 UTC").to_time.utc

I got

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

Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.