como validar si una cadena es en formato hora
Publicado por ytap (4 intervenciones) el 17/11/2006 01:44:14
ayuda porfa:
necesito validar si una cadena esta en formato hora, la cadena la cacho en un formulario strut y ahi valido que sea hora 00:00:00 y me regresa un true si es el formato y un false si no esta dentro del formato.
tengo el siguiente codigo:
public static boolean isValidTime(String cadtex){
Integer h = new Integer(cadtex.substring(0,1));
Integer m = new Integer(cadtex.substring(3,4));
Integer s = new Integer(cadtex.substring(6,7));
Integer hh = new Integer(cadtex.substring(1,2));
if(cadtex.substring(2,3).compareTo(":") != 0){
return false;
}
if(cadtex.substring(5,6).compareTo(":") != 0){
return false;
}
if(!isNotNumber(cadtex.substring(0,2)) && (!isNotNumber(cadtex.substring(3,5))) && (!isNotNumber(cadtex.substring(6,8)))){
return false;
}
if((h.intValue()>3) && (m.intValue()>5) && (s.intValue()>5)) {
return false;
}
if(h.intValue() == 2 && hh.intValue()>5){
return false;
}
else{
return true;
}
}
pero no me funciona, podria alguien ayudarme
necesito validar si una cadena esta en formato hora, la cadena la cacho en un formulario strut y ahi valido que sea hora 00:00:00 y me regresa un true si es el formato y un false si no esta dentro del formato.
tengo el siguiente codigo:
public static boolean isValidTime(String cadtex){
Integer h = new Integer(cadtex.substring(0,1));
Integer m = new Integer(cadtex.substring(3,4));
Integer s = new Integer(cadtex.substring(6,7));
Integer hh = new Integer(cadtex.substring(1,2));
if(cadtex.substring(2,3).compareTo(":") != 0){
return false;
}
if(cadtex.substring(5,6).compareTo(":") != 0){
return false;
}
if(!isNotNumber(cadtex.substring(0,2)) && (!isNotNumber(cadtex.substring(3,5))) && (!isNotNumber(cadtex.substring(6,8)))){
return false;
}
if((h.intValue()>3) && (m.intValue()>5) && (s.intValue()>5)) {
return false;
}
if(h.intValue() == 2 && hh.intValue()>5){
return false;
}
else{
return true;
}
}
pero no me funciona, podria alguien ayudarme
Valora esta pregunta


0