Is their a method in java to check weather a given string is Date or not.
example:
String s="Hello" //is not Date <br>
String s="01/05/2014" //is a valid date
thank You.
Is their a method in java to check weather a given string is Date or not.
example:
String s="Hello" //is not Date <br>
String s="01/05/2014" //is a valid date
thank You.
You can check for a specific format using SimpleDateFormat ex:
DateFormat df = new SimpleDateFormat("mm/dd/yyyy");
try
{
df.parse("01/05/2014");
}
catch(Exception e)
{
//not a date
}
Write simple API that will validate string is date or not,
If isValidDate(String date)
return true
then your string is date otherwise it is not date.
public boolean isValidDate(String date){
SimpleDateFormat dateFormat = new SimpleDateFormat("mm/dd/yyyy");
boolean flag = true;
try{
dateFormat.parse(date);
}catch(ParseException e){
flag = false;
}
return flag;
}