2
I would like to know how to check whether a user-provided input date is valid or not.
2
I would like to know how to check whether a user-provided input date is valid or not.
4
You can use this solution:
public class VerificarData {
public static void main(String[] args) {
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
sdf.setLenient(false);
String dataHoje = "08/12/2014";
try {
Date data = sdf.parse(dataHoje);
System.out.println("A data é válida.");
} catch(ParseException e) {
System.out.println("A data é inválida.");
}
}
}
This solution I use in an application here and it works, I got it in GUJ but I don’t remember the link, so the credit is from who posted there.
setLenient serves to say that there can be no error in the String, if you put for example 10/13/2014 it will return error.
Browser other questions tagged java
You are not signed in. Login or sign up in order to post.
The solution I posted was what you needed? I didn’t understand the date of entry.
– João Neto