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 "dddd, dd MMMM 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 "MM/dd/yyyy".

Custom Patterns

The following custom offset 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.

Character Meaning Example
y or yy Two digit absolute year; a single y allows up to two digits to be parsed, but formats only one digit where possible. 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. Assuming a template value of 2000 (the default): 2012: y => 12
2040: y => 40 - parsing "40" would give a date in 1940
2004: y => 4
2004: yy => 04
yyyy Three digit absolute year. This will parse up to five digits, but only format to as many as are required, with a minimum of three. 1984: parsed to 1984, formatted to "1984"
00123: parsed to year 123, formatted just to "123"
yyyy or yyyyy The absolute year as either always-four or always-five digits. 2012: yyyy => 2012
2012: yyyyy => 02012
Y, YY, YYY, YYYY or YYYYY The year of era, zero-padded as necessary to the same number of characters as the number of 'Y' characters. See notes below. 3 B.C.: YYYY => 0003
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: MM => Dec (can parse from "dec" or "DEC" etc.)
MMMM Full month name, parsed case-insensitively. This is culture-sensitive. (In an English locale.)
June: MMM => Jun (can parse from "june" or "JUNE" etc.)
December: MM => Dec (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: yyyy/MM/dd => 2011/10/09
de-DE: yyyy/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 "yyyy" format.

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.