validation - Date with SimpleDateFormat in Java -
the next code attempts parse date 31-feb-2013 13:02:23
given format.
dateformat dateformat=new simpledateformat("dd-mmm-yyyy hh:mm:ss"); system.out.println(dateformat.parse("31-feb-2013 13:02:23"));
it returns sun mar 03 13:02:23 ist 2013
.
i need invalidate such dates indicating invalid date. (and forth) date shouldn't parsed (or should invalidated in other way). possible?
use dateformat.setlenient(boolean)
method false
argument:
dateformat dateformat=new simpledateformat("dd-mmm-yyyy hh:mm:ss"); dateformat.setlenient(false); system.out.println(dateformat.parse("31-feb-2013 13:02:23"));
java validation date simpledateformat
No comments:
Post a Comment