java.text.Parse异常:不可稀释的日期 [英] java.text.Parse Exception : Unparseable Date
本文介绍了java.text.Parse异常:不可稀释的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下代码:
String ModifiedDate = "1993-06-08T18:27:02.000Z" ;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
Date ModDate = sdf.parse(ModifiedDate);
即使我的日期格式很好,我收到以下异常...
I am getting the following exception even though my date format is fine...
java.text.ParseException: Unparseable date: "1993-06-08T18:27:02.000Z"
at java.text.DateFormat.parse(DateFormat.java:337)
推荐答案
code> Z pattern后缀表示RFC 822时区。你的字符串
The Z
pattern latter indicates an RFC 822 time zone. Your string
String ModifiedDate = "1993-06-08T18:27:02.000Z" ;
不包含这样的时区。它包含一个 Z
字面上。
does not contain such a time zone. It contains a Z
literally.
您将需要一个日期格式,与文字 T
相似,具有文字 Z
。
You'll want a date pattern, that similarly to the literal T
, has a literal Z
.
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
如果您的意图是 Z
表示祖鲁时间,在构建 SimpleDateFormat
If you meant for Z
to indicate Zulu time, add that as a timezone when constructing the SimpleDateFormat
sdf.setTimeZone(TimeZone.getTimeZone("Zulu"));;
这篇关于java.text.Parse异常:不可稀释的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文