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 time 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With