The project needs to validate the format and validity of a field in which the user enters a date with time on the interface. I Google a bit, indeed there are strong people to achieve, including the special circumstances of the leap month, but, because the user is not the same requirements, so if the change of the code of the person is very troublesome. I used another way to adapt to achieve this function, for your reference
For example, the input date time format on the interface is: dd.mm.yyyy hh:mm:ss "2007-02-29 01:00:00"
dd.mm.yyyy hh:mm:ss "2007-02-29 01:00:00"
private int Checkdateformatandvalite (String strdatetime) ... {
Update it according to your requirement.
SimpleDateFormat format = new SimpleDateFormat ("DD. Mm.yyyy HH:mm:ss ");
Try ... {
Date ndate = Format.parse (strdatetime);
String str = Format.format (ndate);
System.out.println (ndate);
System.out.println (str);
System.out.println ("strdatetime=" + strdatetime);
Success
if (Str.equals (strdatetime))
return 1;
DateTime is not validate
Else
return 0;
catch (Exception e) ... {
E.printstacktrace ();
Format error
return-1;
}
}