Saturday, May 11, 2013

String Date to DateBox

@UiField DateBox dbTo;
@UiField DateBox dbFrom;

String fromDate = formatMIT2DDMMYYYY(p_result.getHeaderDataList().get(i).getT4()) ;
String toDate =formatMIT2DDMMYYYY(p_result.getHeaderDataList().get(i).getT5()) ;

Date d1 = new DateBox.DefaultFormat(DateTimeFormat.getFormat("dd/MM/yyyy")).parse(dbFrom, fromDate , false );
dbFrom.setValue(d1) ;


Date d2 = new DateBox.DefaultFormat(DateTimeFormat.getFormat("dd/MM/yyyy")).parse(dbFrom, toDate , false );
dbTo.setValue(d2) ;


public static String formatMIT2DDMMYYYY(String p) {
        String ret="";
        try{
           int y = Integer.parseInt(   p.substring(0, 4)  );    
           int m = Integer.parseInt(   p.substring(4, 6)  );           
           int d = Integer.parseInt(   p.substring(6, 8)  );
           ret = d + "/" + m + "/" + y ;
           ret = p.substring(6, 8)+"/" + p.substring(4, 6)+"/"+ p.substring(0, 4);
        } catch (Exception ex){}
        return ret;
}

No comments:

Post a Comment