简体   繁体   English

解析日期字符串的问题

[英]Issue with parsing Date string

I'm trying to parse the following string to a Date object: 我正在尝试将以下字符串解析为Date对象:

2013-12-26T01:00:56.664Z

Using this SimpleDateFormat : 使用这个SimpleDateFormat

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");

But I'm getting a: 但是我得到了:

 java.text.ParseException: Unparseable date: "2013-12-26T01:00:56.664Z" (at offset 19)

What am I doing wrong, How I should handle the T and the Z letters in the date? 我做错了什么,我该如何处理日期中的TZ字母?

The real isssue with the date is not T & Z but the milliseconds. 真实的问题是日期不是T&Z而是毫秒。

"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" This must be the format that is to be used becaue there are milli seconds as well in the input date. "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"这必须是要使用的格式,因为在输入日期也有毫秒。

You can use this 你可以用它

String date = "2013-12-26T01:00:56.664Z";
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
try {
   System.out.println(sdf.parse(date)); // Result Thu Dec 26 01:00:56 CET 2013
} catch (ParseException e) {
   e.printStackTrace();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM