I'm using a SimpleDateFormatter to parse a date/time. The problem is that if the time I insert is bigger than 24 it passes to the next day.
How can I do a date/time validation with strict time (between 0 and 24 -- I don't want a tim开发者_JAVA百科e of 25:00 to be interpreted as 1 day and 1 hour).
Thank you.
setLenient(false)
Should do what you want.
DateFormat.setLenient(boolean);
This will throw an Unparseable date: "25:00"
exception:
final DateFormat formatter = SimpleDateFormat.getTimeInstance(DateFormat.SHORT);
formatter.setLenient(false);
formatter.parse("25:00");
lenient
by default is true
.
精彩评论