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.
ISO 8601 represents date and time by starting with the year, followed by the month, the day, the hour, the minutes, seconds and milliseconds. For example, 2020-07-10 15:00:00.000, represents the 10th of July 2020 at 3 p.m. (in local time as there is no time zone offset specified—more on that below).
For example, the ISO standard defines the year format as YYYY, the year/month format as YYYY-MM, and the year/month/day format as either YYYYMMDD (basic format) or YYYY-MM-DD (extended format).
Time zone designators. Time zones in ISO 8601 are represented as local time (with the location unspecified), as UTC, or as an offset from UTC.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With