我试图获取一个Time对象,其格式包括毫秒:
x = Time.zone.parse("12-1-1998 00:00:00.000", "%Y-%m-%d %H:%M:%S.%3N")
添加格式时出错:
undefined method `year' for "%Y-%m-%d %H:%M:%S.%3N":String (NoMethodError)
我也试过Time.zone.parse("12-1-1998 00:00:00.000")
,但我明白了:
1998-01-12T00:00:00Z
我需要时间看起来像这样:
1998-01-12T00:00:00.000Z
答案 0 :(得分:2)
datetime = DateTime.strptime("2011-05-21 04:20:46.011", "%Y-%m-%d %H:%M:%S.%L")
datetime.strftime("%Y-%m-%dT%H:%M:%S.%LZ")
=> "2011-05-21T04:20:46.011Z"