Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
parseこれら 2 つのステートメントが異なる結果を返すのはなぜですか?
parse
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
input にタイムゾーン情報がありませんString。DateTime.parseしたがって、UTC を想定しています。Time.parse現地時間を想定しており、UTC + 2にいると思います。
String
DateTime.parse
Time.parse
>> 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"