Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

validate date java

The current way is to use the calendar class. It has the setLenient method that will validate the date and throw and exception if it is out of range as in your example.

Forgot to add: If you get a calendar instance and set the time using your date, this is how you get the validation.

Calendar cal = Calendar.getInstance();
cal.setLenient(false);
cal.setTime(yourDate);
try {
    cal.getTime();
}
catch (Exception e) {
  System.out.println("Invalid date");
}
Comment

PREVIOUS NEXT
Code Example
Java :: fileinputstream 
Java :: split number java 
Java :: how to get data from radio group in android 
Java :: set java path on linux ubuntu 
Java :: No Java executable found in current PATH: /bin:/usr/bin:/sbin:/usr/sbin 
Java :: find first element of list java 
Java :: arrays in java 
Java :: imageview height based on screen size 
Java :: milliseconds to seconds java 
Java :: how to check if the file has remaining without reading from it java 
Java :: sort an int array java 
Java :: last char in string java 
Java :: convert javascritp getTime() to datetime 
Java :: fill two dimensional array rows by rows java 
Java :: length of array in java 
Java :: java unit test an api 
Java :: create a list java 
Java :: volley library 
Java :: java math power 
Java :: java currency format 
Java :: how to print byte array in java 
Java :: java  
Java :: all installed java 
Java :: iterate hashmap java 
Java :: java convert double to int 
Java :: throw error java 
Java :: Caused by: java.lang.ClassNotFoundException 
Java :: how to scan as a letter in java 
Java :: regex pattern for valid logins 
Java :: java check if path exists 
ADD CONTENT
Topic
Content
Source link
Name
8+6 =