Karen
Karen

Reputation: 275

GregorianCalendar months

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?

Upvotes: 0

Views: 189

Answers (1)

akf
akf

Reputation: 39485

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.

Upvotes: 1

Related Questions