我从json响应中提取了一个字符串“2015-11-01T10:00:00.00 08:00”.如何将其转换为时间或日期时间? 我尝试了Time.new(“2015-11-01T10:00:00.00 08:00”)它返回2015-01-01 00:00:00 0530,显然日期也在这
我尝试了Time.new(“2015-11-01T10:00:00.00 08:00”)它返回2015-01-01 00:00:00 0530,显然日期也在这里改变了.
require 'date' ▶ Date.parse "2015-11-01T10:00:00.00+08:00" #⇒ #<Date: 2015-11-01 ((2457328j,0s,0n),+0s,2299161j)> ▶ DateTime.parse "2015-11-01T10:00:00.00+08:00" #⇒ #<DateTime: 2015-11-01T10:00:00+08:00 ((2457328j,7200s,0n),+28800s,2299161j)>
或者,甚至更好:
▶ DateTime.iso8601 "2015-11-01T10:00:00.00+08:00" #⇒ #<DateTime: 2015-11-01T10:00:00+08:00 ((2457328j,7200s,0n),+28800s,2299161j)>