[英]ParseException when using SimpleDateFormat
I'm trying the following code and I keep getting the exception: 我正在尝试以下代码,但不断收到异常:
java.text.ParseException: Unparseable date: "2015-11-05T16:24:55+02:00"
java.text.ParseException:无法解析的日期:“ 2015-11-05T16:24:55 + 02:00”
My code goes as the following: 我的代码如下:
formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
date = formatter.parse(dateValue);
My Date Input is: 我的日期输入是:
2015-11-05T16:24:55+02:00
2015-11-05T16:24:55 + 02:00
and I would like to translate it to: 我想将其翻译为:
05-11-2015 T16:24:55+02:00
2015/05/11 T16:24:55 + 02:00
If you use Java 7+ you can simply replace the Z
by an X
. 如果您使用Java 7+,则只需将
X
替换为Z
即可。 More information about the difference between Z
(RFC822) and X
(ISO 8601) is available in the javadoc . javadoc中提供了有关
Z
(RFC822)和X
(ISO 8601)之间区别的更多信息。
If you are on Java 6 or earlier, you will need to remove the :
in the original string, something like: 如果您使用的是Java 6或更早版本,则需要删除原始字符串中的
:
,例如:
date = formatter.parse(dateValue.replaceAll(":(\\d+)$", "$1"));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.