I need to validate a string whether it is in the format ISODateTimeFormat.dateTimeNoMillis().
final DateTimeFormatter dateHourMinuteSecondFormatter =ISODateTimeFormat.dateTimeNoMillis();
String s = "2012-W12-12";
try {
dateHourMinuteSecondFormatter.parseDateTime(s);
} catch (IllegalArgumentException e) {
e.setMessage("exception thrown);
}
It is supposed to throw the exception as the date is in the wrong format but it is not.
Is there anything else that I need to add?
No, there’s nothing more you need to do.
I suspect that actually it is throwing the example, but your message diagnostics are incorrect. This certainly fails for me, using Joda Time 2.1:
Output: