-2

Possible Duplicate:
Improper result of SimpleDateFormat

The following code outputs a date of 00/12/2010. I can't figure out why the date string is parsed without exception but the month is set to 00. I tried using a second argument to the SimpleDateFormat constructor of Locale.Enlgish for sanity's sake but that didn't help. Any suggestions?

    String dateString = "12-OCT-10";
    SimpleDateFormat formatFrom = new SimpleDateFormat("dd-MMM-yy");
    Date date = formatFrom.parse(dateString);
    SimpleDateFormat formatTo = new SimpleDateFormat("mm/dd/yyyy");
    System.out.println(formatTo.format(date));
Community
  • 1
  • 1
Mario
  • 369
  • 1
  • 2
  • 16
  • 2
    Your first stop should be [the documentation](http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html). Then [a search](https://www.google.com/search?q=wrong+month+simpledateformat+site%3Astackoverflow.com). :-) – T.J. Crowder Jul 06 '12 at 18:10
  • Couldn't agree more. I read the documentation and I'm aware that lowercase 'm' is for minutes which is why I use uppercase 'M' in the first SimpleDateFormat. I just goofed on the second one. Stupid mistake. Seriously wish I could delete this post. Thanks for the help though. – Mario Jul 06 '12 at 18:13

1 Answers1

13

The mm is for minute, use MM; see the documentation for details.

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
Matzi
  • 13,770
  • 4
  • 33
  • 50
  • See also: http://stackoverflow.com/questions/11356109/improper-result-of-simpledateformat/ same issue – jmj Jul 06 '12 at 18:05
  • 1
    Geez, you gotta be kidding me. I can't believe I did that and wasted an hour on this. Thanks for being an extra set of eyes. – Mario Jul 06 '12 at 18:07