I was working on a component for credit card processing where I needed to get the months of the year. Trying to plan ahead, I decided to use the DateFormatSymbols so it could easily handle localization if it ever needed to be used in a different language.
It wasn’t doing what I expected and I finally found the problem with the following code:
DateFormatSymbols symbols = new DateFormatSymbols(); String months = symbols.getMonths(); int numOfMonths = months.length System.out.println(numOfMonths);
The output is 13. If you list all of the strings in the
months array, you’ll find the first 12 are what you’d expect, but there is a 13th blank month at the end.
It turns out that there are some lunar based calendars that have to add a “leap month” every so many years. This month is called Undecimber and comes after December. However, I’m not clear why Java is giving me a blank month. If the given locale only has 12 months, what is the value of giving back a 13 item array and just leaving one blank?
2 Replies to “Java Thinks There Are 13 Months”
I tried to reply your post but the output is 12. is this has change 1.5->1.6 jdk ?
I don’t think it has changed. What platform are you on?