I'm trying to parse a timestamp with timezone string in Java. My strings are:
"2013-01-01 15:30:00.2 +05:00"
"2003-01-01 02:59:04.123 -8:00"
This is my code to parse it:
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS z");
simpleDateFormat.parse("2013-01-01 15:30:00.2 +05:00");
However, I'm getting this error message when I run the code:
java.text.ParseException: Unparseable date: "2013-01-01 15:30:00.2 +05:00"
I also tried using the following code to parse it:
DateTimeFormatter dateTimeFormatter = ISODateTimeFormat.dateTimeNoMillis();
DateTime dateTime = dateTimeFormatter.parseDateTime("2003-01-01 02:59:04.123 -8:00");
Timestamp timeStamp = new Timestamp(dateTime.getMillis());
This gives me exception:
Invalid format: "2003-01-01 02:59:04.123 -8:00" is malformed at " 02:59:04.123 -8:00"
I also tried inserting 'T' in the string after date but it also gave the invalid format exception:
Invalid format: "2003-01-01T02:59:04.123 -8:00" is malformed at " .123 -8:00"
This must be really simple -- I don't know where I'm going wrong though.
Thanks for the help!