简体   繁体   中英

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"

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

and I would like to translate it to:

05-11-2015 T16:24:55+02:00

If you use Java 7+ you can simply replace the Z by an X . More information about the difference between Z (RFC822) and X (ISO 8601) is available in the javadoc .

If you are on Java 6 or earlier, you will need to remove the : in the original string, something like:

date = formatter.parse(dateValue.replaceAll(":(\\d+)$", "$1"));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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