I am beginner in Java and JSP. I  need validate a date that I caught in a
JSP. The format of the date in the JSP is ddMMaaaa (String). I must
validate it and keep it in a numeric format (int)  whit format aaaaMMdd.

I am making the following bean. Are there a simpler ways?.   Sorry by my
English.

import java.util.*;
import java.text.*;

public class Fecha {

     private Locale localidad = new Locale ("ES", "ES", "Traditional_WIN");
     private String patronAMD = "yyyyMMdd";
     private String patronDMA = "ddMMyyyy";
     private SimpleDateFormat formatoAMD = new SimpleDateFormat (patronAMD,
localidad);
     private SimpleDateFormat formatoDMA = new SimpleDateFormat (patronDMA,
localidad);
     private   ParsePosition pos = new ParsePosition(0);


public Fecha() {
     super();
}

public String aAMD(String fechaDMA) {

     Date variableFecha = formatoDMA.parse(fechaDMA, pos);
     return formatoAMD.format(variableFecha);
}

public String aDMA(String fechaAMD) {
     Date variableFecha = formatoAMD.parse(fechaAMD, pos);
     return formatoDMA.format(variableFecha);
}


public boolean validaAMD(String fecha) {

     Fecha f1= new Fecha();
     Fecha f2= new Fecha();
     String fechaAux1;
     String fechaAux2;

     fechaAux1 = f1.aDMA(fecha);
     fechaAux2 = f2.aAMD(fechaAux1);


     if (fechaAux2.equals(fecha))
       return true;
     else return false;

}
}

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to