El valor de la fecha no se muestra correctamente

Hello all i am stuck in problem with custom property editors.Following are my code *fragments:*

  import java.beans.PropertyEditorSupport;
  import java.text.DateFormat;
  import java.text.SimpleDateFormat;
  import java.util.Calendar;
  import java.util.Date;
  import org.joda.time.format.DateTimeFormatter;
  import org.joda.time.format.ISODateTimeFormat;
  public class CustomCalendarEditor extends PropertyEditorSupport {

         private  Date date;
         @Override
         public String getAsText() {
           Calendar value = (Calendar) getValue();
           Date dateTime = value.getTime();
           System.out.println("in editor--->"+dateTime);
           return dateTime.toString();
         }
         @Override
         public void setAsText(String text) throws IllegalArgumentException {
           try { 
               DateFormat formatter ; 
               Date date ; 
               formatter = new SimpleDateFormat("dd/MM/yyyy");
               date = (Date)formatter.parse(text); 
               Calendar cal=Calendar.getInstance();
               cal.setTime(date);
               System.out.println("Today is " +date );
               setValue(cal);
          }catch(Exception e){
               e.printStackTrace();
         }}
   }

Desde arriba getAstext method I am converting Calendar object to date for displaying in spring form like following:

form:input path="dateTime" value=" ${catalogingInfo.dateTime}"

getAstext is getting called but date is not displayed in proper format it is showing like:

java.util.GregorianCalendar[time=?,areFieldsSet=false,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="Asia/Calcutta",offset=19800000,dstSavings=0,useDaylight=false,transitions=6,lastRule=null],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2011,MONTH=5,WEEK_OF_YEAR=1,WEEK_OF_MONTH=1,DAY_OF_MONTH=6,DAY_OF_YEAR=1,DAY_OF_WEEK=5,DAY_OF_WEEK_IN_MONTH=1,AM_PM=0,HOUR=0,HOUR_OF_DAY=0,MINUTE=0,SECOND=0,MILLISECOND=0,ZONE_OFFSET=19800000,DST_OFFSET=0]

I am not sure where I am making a mistake. Sorry for my bad English.

preguntado el 31 de julio de 12 a las 15:07

1 Respuestas

Right, because you can not use toString to format date or calendar. Use SimpleDateFormat class and the format operation

Respondido 31 Jul 12, 15:07

i understand but atleast it should display like Thu Jun 09 00:00:00 IST 2011 - Piyush colgando

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.