Pregunta

GregorianCalendar startDate = new GregorianCalendar(2009, Calendar.JANUARY, 1);
SimpleDateFormat sdf = new SimpleDateFormat("d/m/yyyy"); 
public void setStart()
{
    startDate.setLenient(false);
    System.out.println(sdf.format(startDate.getTime()));
}

Cuando ejecuto este código, obtengo 1/0/2009. También obtengo lo mismo cuando cambio los meses. ¿Qué tiene de malo y cómo puedo solucionarlo?

¿Fue útil?

Solución

La 'm' minúscula es por minuto en hora. En su lugar, debe usar la 'M' mayúscula.

SimpleDateFormat sdf = new SimpleDateFormat("d/M/yyyy"); 

Consulte SimpleDateFormat JavaDoc para más detalles.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top