I am trying to parse a Date represented as a String. An example of the String would be: 20150724T104139.118+02
There is the parsing code:
DateFormat formatter = new SimpleDateFormat(timestampFormat);
return formatter.parse("yyyyMMdd'T'HHmmss'.'SX");
which throws error:
java.text.ParseException: Unparseable date: "20150724T104139.118+02"
at java.text.DateFormat.parse(DateFormat.java:366)
at
The pattern is the same I use when transforming a Date into that string.
First of all, you have erroneously swapped the SimpleDateFormat
string and the string you want to parse the date from. Also the format string doesn't match the example date. You need S
three times for the milliseconds. Try the following :
String text = "20150724T104139.118+02";
DateFormat formatter = new SimpleDateFormat("yyyyMMdd'T'HHmmss'.'SSSX");
Date myTime = formatter.parse(text);