Alla fine in qualche modo ho risolto..
Riporto il metodo per il controllo della validità della data,
per l'ora e per il formato della data ho utilizzato un' espressione regolare
in Javascript nella JSP che presenta i risultati
public static boolean dataValido(String dataNew) {
String formatoModi = "dd/MM/yyyy";
try {
if (dataNew.equals(""))
return true;
SimpleDateFormat formatter1 = new SimpleDateFormat(formatoModi);
long dataInserita = formatter1.parse(dataNew).getTime();
long dataCorrente = Calendar.getInstance().getTime().getTime();
if(dataInserita > dataCorrente)
return false;
return dataEsistente(formatter1, dataNew);
} catch (Exception e) {
return false;
}
}
public static boolean dataEsistente(SimpleDateFormat formatter, String dataNew) {
boolean exist =true;
try {
int giorno = Integer.parseInt(dataNew.substring(0, 2));
if(giorno<1)
return false;
int mese = Integer.parseInt(dataNew.substring(3, 5));
if(mese<1 || mese>12)
return false;
int anno = Integer.parseInt(dataNew.substring(6));
if(mese==1 || mese==3 || mese==5 || mese==7 || mese==8 || mese==10 || mese==12){
if(giorno>31)
return false;
}
if(mese==4 || mese==6 || mese==9 || mese==11){
if(giorno>30)
return false;
}
if(mese==2){
if(annoBisestile(anno)){
if(giorno>29)
return false;
}
else
if(giorno>28)
return false;
}
} catch (NumberFormatException e) {
return false;
}
return exist;
}
/*
* Stabilisce se un anno è bisestile o meno
*/
public static boolean annoBisestile(int anno) {
if((anno%400==0) || ((anno%4==0) && (anno%100!=0)))
return true;
else
return false;
}
Grazie![]()

Rispondi quotando