ict1991
ict1991

Reputation: 2110

Why is the date being incorrectly converted?

I'm trying to convert a String date into a Date object like this:

  DateFormat formatter ; 
  Date date ; 
  formatter = new SimpleDateFormat("dd/mm/yyyy");
  date = (Date)formatter.parse(str_date); 

Source

However for some reason, the month is being converted into january always.

Example inputted date: 18/08/2012 Outputted date: Wed Jan 18 00:08:00 CET 2012

Does anyone know why this is happening please?

Upvotes: 0

Views: 74

Answers (1)

MByD
MByD

Reputation: 137442

It should be "dd/MM/yyyy" (upper case M). Lower case m is for minutes.

Take a look at the table in SimpleDateFormat docs.

Upvotes: 9

Related Questions