Is it possible to have month 13 on a date in Java?


I was looking at the documentation for class Formatter of Java 7, on this link of Oracle itself , when I noticed the following example below:

What intrigued me was the example given for the month formatting option, m : which are the numbers from 1 to 13.

All the examples given for the other formatting options are valid and have consistent values, which leads me to believe that yes, it is possible to have a month 13 in Java. The question is, what date is UTC, and on which calendar, would I return a month 13?

Or is this actually the only example of the page that does not match reality, and the value 13 was typed by chance, without thinking?

asked by anonymous 23.04.2015 / 21:08

2 answers


Looking further down, the documentation you've linked has the same snippet repeated, only this time with a more detailed explanation, and it says:


Month, formatted the two digits with leading zeros as necessary, ie 01 - 13, where "01" is the first month of the year and ("13" is a special value required to support lunar calendars). >

Free translation:


Month, formatted with two digits with zero prefixed when needed. Ex: 01 to 13, where "01" is the first month of the year and ("13" is a special value required to support lunar calendars).

The name of the month in English is UNDECIMBER :


Value of the MONTH field indicating the thirteenth month of the year. Although GregorianCalendar does not use this value, lunar calendars do.

Free translation:


MONTH field value indicating the thirteenth month of the year. Although the GregorianCalendar does not use this value, lunar calendars use it.

(In) Fortunately, there is no standard Java class that supports the lunar calendar, but it is possible to find implementations made by lunatics like this here: hoveychen / lunar_calendar @ GitHub

When you try to use month 13 on a Gregorian calendar object, we get the first month of the next year. Example:

import java.util.Calendar;

public class Lunatico {
    public static void main(String[] args) {
        Calendar c1 = Calendar.getInstance();
        c1.set(2015, Calendar.DECEMBER, 20);   //data: 20/12/2015

        Calendar c2 = Calendar.getInstance();
        c2.set(2015, Calendar.UNDECIMBER, 20); //data: 20/13/2015

        System.out.println(String.format("Dia normal: %1$te/%1$tm/%1$tY", c1));
        System.out.println(String.format("Dia (quase) lunático: %1$te/%1$tm/%1$tY", c2));

        System.out.println(String.format("\nMês: %1$tB", c2)); //escrevendo por extenso



Normal day: 12/20/2015
  Day (almost) whimsical: 01/20/2016


Month: January

Notice that within String.format() I used m , as explained in the documentation.

23.04.2015 / 21:14

Some calendars can be 13 months old, such as the igbo calendar .

The main reason for a lunar calendar to have 13 months is that each lunar cycle has 28 days approximately (4 weeks). If we multiply 28 by 13, the result is 364 days. That is, in a year we have 13 complete lunar cycles (and another 1 or 2 days left). In purely lunar calendars, each lunar cycle corresponds to one month, and therefore the year would have 13 months.

However, not all 13-month calendars are necessarily lunar, such as the Coptic calendar and the Ethiopian calendar . In these calendars we have 12 months with 30 days each and a short thirteenth month, with only 5 days.

Some other calendars, although based on lunar cycles, have 12 months, such as the Islamic calendar and < a href=""> Hindu calendar .

In a few years, the Hebrew calendar has a thirteenth leap month as well.

The name of the thirteenth month is unde Dezembro , which would be the eleventh month (not counting January and February), because December was the tenth month before the Romans reformed the calendar in the year 46 BC . Likewise, the fourteenth month, for calendars where this may exist, is called duodeDecember .

23.04.2015 / 21:59