Patterns for LocalDate values

The LocalDate type supports the following patterns:

Standard Patterns

The following standard patterns are supported:

  • d: Short format pattern.
    This is the short date pattern as defined by the culture's DateTimeFormatInfo.ShortDatePattern. For example, in the invariant culture this is "MM/dd/yyyy".

  • D: Long format pattern.
    This is the long date pattern as defined by the culture's DateTimeFormatInfo.LongDatePattern. For example, in the invariant culture this is "dddd, dd MMMM yyyy". This is the default format pattern.

Custom Patterns

The following custom format pattern characters are supported for local dates. See custom pattern notes for general notes on custom patterns, including characters used for escaping and text literals.

For the meanings of "absolute" years and text handling, see later details.

de-DE: uuuu/MM/dd => 2011.10.09
Character Meaning Example
yy Two digit year of era, in the range 0-99. When parsing, the "base century" is chosen from the template value; if the two-digit year is greater than 30, the corresponding year in the previous century is used, unless the century of the template value is already the first century of the era. If the template value is in the first century and the input is "00", an exception will be thrown on parsing. Note that when formatting, no checking is performed to ensure that the year will be parsed to the same value. (For example, 1725 would be formatted as 25 but parsed as 2025.) In general, use of this pattern specifier is discouraged, on the grounds of it leading to ambiguity. Assuming a template value of 2000 (the default): 2012: yy => 12
2040: yy => 40 - parsing "40" would give a date in 1940
yyyy The year of era as 4 digits. 2000 A.D. (ISO calendar, en-US): yyyy g => 2000 A.D. 13 B.C. (ISO calendar, en-US): yyyy g => 0013 B.C.
u, uu, uuu, uuuu The absolute, zero-padded as necessary to the same number of characters as the number of 'u' characters, with an optional leading - sign. See notes below. 3 B.C.: uuuu => -0002
g or gg The name of the era. This is calendar and culture specific. See notes below. 13 B.C. (ISO calendar, en-US): y g => 13 B.C.
M or MM Month of year specified as a number. MM is zero-padded; M is not. June: M => 6
June: MM => 06
December: M => 12
December: MM => 12
MMM Abbreviated month name, parsed case-insensitively. This is culture-sensitive. (In an English locale.)
June: MMM => Jun (can parse from "jun" or "JUN" etc.)
December: MMM => Dec (can parse from "dec" or "DEC" etc.)
MMMM Full month name, parsed case-insensitively. This is culture-sensitive. (In an English locale.)
June: MMMM => June (can parse from "june" or "JUNE" etc.)
December: MMMM => December (can parse from "december" or "DECEMBER" etc.)
d or dd Day of month - dd is zero-padded; d is not. 1st of the month: d => 1 (would parse "01" as well)
1st of the month: dd => 01
21st of the month: d => 21
21st of the month: dd => 21
ddd Abbreviated day-of-week name, parsed case-insensitively. When parsing, the parsed day of week is validated against the computed date, but does not affect the calculations of that date. This value is culture-sensitive. February 4th 2012 (a Saturday)
en-US: Sat fr-FR: sam.
dddd Full day-of-week name, parsed case-insensitively. When parsing, the parsed day of week is validated against the computed date, but does not affect the calculations of that date. February 4th 2012 (a Saturday)
en-US: Saturday fr-FR: samedi
c The Noda-specific calendar system ID. This would rarely be appropriate for user-visible text, but allows exact round-tripping when serializing values via text. ISO
Coptic 3
Hijri Astronomical-Base16
/ The date separator for the format provider; slash in the invariant culture. en-US: uuuu/MM/dd => 2011/10/09
de-DE: uuuu/MM/dd => 2011.10.09

Notes

Absolute and era years

Some calendars support multiple eras. For example, the ISO calendar supports the B.C. / B.C.E. and A.D. / C.E. eras. A mapping is provided between "year within era" and "absolute" year - where an absolute year uniquely identifies the date, and does not generally skip. In the ISO calendar, the absolute year 0 is deemed to be 1 B.C. and the absolute year 1 is deemed to be 1 A.D. thus giving a simplified arithmetic system.

Negative absolute years can be both parsed and formatted - so "13 B.C." would be formatted as "-0012" using the "uuuu" format.

Note that the meaning of the "y" specifier has changed over time: in Noda Time 1.x, this meant "absolute year"; it now means "year of era" to be consistent with the BCL. (This used to be handled by the "Y" specifier.) The "u" specifier is now used for "absolute year".

Text sources

Noda Time comes with its own limited set of era names, but month and day names are taken from the .NET framework. Unfortunately these are not available on a per-calendar basis, so the same names are used for all calendars, based solely on culture. It is hoped that future release of Noda Time may use information from the Unicode CLDR to provide a more comprehensive treatment.

Hebrew month names

The Hebrew calendar has two month numbering systems (scriptural and civil), each with their own benefits and drawbacks. Both have issues for text handling: as of Noda Time 1.3.0, the civil month numbering is assumed as that corresponds with the BCL month numbering... but due to the inclusion of a leap month, the month name/number correspondence changes in a leap year. Until this is fixed, it is strongly recommended that you only use month numbers in any textual representations of dates in the Hebrew calendar. Additionally, you may wish to consider how to best clarify whether that month number is in the scriptural or civil numbering system.