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.

Character Meaning Example
y or yy Two digit absolute year with an optional leading - sign; a single y allows up to two digits to be parsed, but formats only one digit where possible. 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. 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.) 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
yyy Three digit absolute year with optional leading - sign. 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 The absolute year as 4 or 5 digits with an optional leading - sign.

If the absolute year is outside the range [-9999, 9999] the value will be formatted (with the excess digit), but the result may not be parsed back to the original value. If the next character in the pattern represents a literal non-digit, or a non-alphanumeric character, or this appears at the end of the pattern, then up to five digits will be parsed. Otherwise, only exactly 4 digits will be parsed.

This is to avoid a pattern such as "yyyyMMdd" from becoming ambiguous or hard to parse, while allowing "yyyy-MM-dd" to handle 5-digit years in a convenient fashion. (The detection of "5 digits would be okay" is quite conservative; "yyyyVMMdd" wouldn't handle 5-digit years, but "yyyy'V'MMdd" would, even though the two patterns are otherwise equivalent. This algorithm may change over time.)

yyyyy The absolute year as exactly 5 digits with an optional leading - sign. 2012: => 02012
12345: => 12345
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: 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: 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.

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.