Search code examples
datedatetimeiso8601java-time

Is the --MM-DD format for month-day part of ISO 8601?


The Java 8 date/time API, java.time, has a MonthDay class to represent a month and a day together. So too the Joda-Time library offers a MonthDay class.

In java.time, the MonthDay.toString() method is declared as:

Outputs this month-day as a String, such as --12-03.

Most of the classes in java.time have their toString() method output the standard ISO 8601 representation of the concept they represent (YYYY-MM-DD for LocalDate, for example), so I would expect this --MM-DD format to be standard as well.

But I could not find this in the ISO 8601 standard.

Is month-day a concept defined by ISO 8601, and if so, is --MM-DD the standard format?

Background: I'm developing a date/time API in another language.


Solution

  • Yes, in paragraph 4.4, ISO 8601:1988 says:

    Note - The hyphen is also used to indicate omitted components

    So the format --MM-DD conforms to ISO 8601, where the year is omitted/missing, and paragraph 5.2.1.3d also contains an example of that very format.

    This format disappeared in later editions of the ISO 8601 standard. However, the java.time classes continue to support the format along with the MonthDay class.