Idan Wender
Idan Wender

Reputation: 987

Time.parse and DateTime.parse returns different results

Why do these two parse statements return different results?

time = "13:30:0"

DateTime.parse(time).to_time.utc
#=>  2013-10-13 13:30:00 UTC

Time.parse(time).utc
#=>  2013-10-13 11:30:00 UTC

Upvotes: 4

Views: 1894

Answers (1)

Jakob S
Jakob S

Reputation: 20125

There is no timezone information in the input String. DateTime.parse therefore assumes UTC. Time.parse assumes local time, and I guess you're in UTC+2.

>> time = "13:30:0"
=> "13:30:0"
>> DateTime.parse(time).to_s
=> "2013-10-13T13:30:00+00:00"
>> Time.parse(time).to_s
=> "2013-10-13 13:30:00 +0200"

Upvotes: 12

Related Questions