views:

53

answers:

1
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()));
}

When I run this code, I get 1/0/2009. I also get the same thing when I change the months. What is wrong with it and how can I fix it?

+1  A: 

The lowercase 'm' is for minute in hour. You should use the uppercase 'M' instead.

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

See the SimpleDateFormat JavaDoc for more details.

akf