[英]java.text.ParseException: Unparseable date “yyyy-MM-dd'T'HH:mm:ss.SSSZ” - SimpleDateFormat
I am suffering error from this code 我正在从此代码中遇到错误
java.text.ParseException: Unparseable date: "1998-09-17T00:00:00.000+08:00" (at offset 23)
I not sure what wrong with the code 我不确定代码有什么问题
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
Date date = null;
try
{
date = sdf.parse(startdate);
}
catch(Exception ex)
{
ex.printStackTrace();
}
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss.SSS");
String dateStr = formatter.format(date);
System.out.println(dateStr);
What should I do? 我该怎么办?
The timezone format is not correct. 时区格式不正确。
The Timezone should be +0800
not +08:00
. 时区应为
+0800
而不是+08:00
。
According to the samples in the Javadocs for SimpleDateFormat
, you should be fine with 根据Javadocs中用于
SimpleDateFormat
的示例,您应该对
"yyyy-MM-dd'T'HH:mm:ss.SSSXXX" -> 2001-07-04T12:08:56.235-07:00
XXX
is the ISO Format, that will allow the colon in the timezone. XXX
是ISO格式,可以在时区中使用冒号。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.