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语句返回不同的结果?
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
输入中没有时区信息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"