Just delete the m. partly through string manipulation. This is redundant.
Instead of simple parsing SimpleDateFormat.
Something like that:
String whatever = "2013-05-23T09:18:07 pm.380+0000"; whatever = whatever.replaceAll(" pm.", ":").replaceAll(" am.", ":"); System.out.println(whatever); S String pattern = "yyyy-MM-dd'T'hh:mm:ss:SSS'Z'"; SimpleDateFormat format = new SimpleDateFormat(pattern, Locale.US); Date date; try { date = format.parse(whatever); System.out.println(date); } catch (ParseException e) {
Update
As indicated by the IAN, I missed that the watch is not in a 24-hour format. However, I received part of a millisecond and added part of a time zone to John Skeet's answer to get:
String text = "2013-05-23T09:18:07 pm.380+0000"; String pattern = "yyyy-MM-dd'T'hh:mm:ss aa'.'SSSZ"; SimpleDateFormat format = new SimpleDateFormat(pattern); DateFormatSymbols symbols = format.getDateFormatSymbols(); symbols = (DateFormatSymbols) symbols.clone(); symbols.setAmPmStrings(new String[] { "am", "pm"}); format.setDateFormatSymbols(symbols); Date date = format.parse(text); System.out.println(date);
source share