Class ZonedDateTimePattern
Represents a pattern for parsing and formatting ZonedDateTime values.
Since 1.2.x
Availability net6.0, net8.0, netstandard2.0
Implements
Inherited Members
Namespace: NodaTime.Text
Assembly: NodaTime.dll
Syntax
public sealed class ZonedDateTimePattern : IPattern<ZonedDateTime>
Properties
ExtendedFormatOnlyIso
Returns an invariant zoned date/time pattern based on ISO-8601 (down to the nanosecond) including offset from UTC and zone ID.
It corresponds to a custom pattern of "uuuu'-'MM'-'dd'T'HH':'mm':'ss;FFFFFFFFF z '('o<g>')'" and is available
as the 'F' standard pattern.
Since 1.4.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public static ZonedDateTimePattern ExtendedFormatOnlyIso { get; }
Property Value
| Type | Description |
|---|---|
| ZonedDateTimePattern | An invariant zoned date/time pattern based on ISO-8601 (down to the nanosecond) including offset from UTC and zone ID. |
Remarks
The calendar system is not formatted as part of this pattern, and it cannot be used for parsing as no time zone
provider is included. Call WithZoneProvider(IDateTimeZoneProvider?) on the value of this property to obtain a
pattern which can be used for parsing.
GeneralFormatOnlyIso
Gets an zoned local date/time pattern based on ISO-8601 (down to the second) including offset from UTC and zone ID.
It corresponds to a custom pattern of "uuuu'-'MM'-'dd'T'HH':'mm':'ss z '('o<g>')'" and is available
as the 'G' standard pattern.
Since 1.4.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public static ZonedDateTimePattern GeneralFormatOnlyIso { get; }
Property Value
| Type | Description |
|---|---|
| ZonedDateTimePattern | An zoned local date/time pattern based on ISO-8601 (down to the second) including offset from UTC and zone ID. |
Remarks
The calendar system is not formatted as part of this pattern, and it cannot be used for parsing as no time zone
provider is included. Call WithZoneProvider(IDateTimeZoneProvider?) on the value of this property to obtain a
pattern which can be used for parsing.
PatternText
Gets the pattern text for this pattern, as supplied on creation.
Since 1.2.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public string PatternText { get; }
Property Value
| Type | Description |
|---|---|
| string | The pattern text for this pattern, as supplied on creation. |
Resolver
Gets the resolver which is used to map local date/times to zoned date/times,
handling skipped and ambiguous times appropriately (where the offset isn't specified in the pattern).
This may be null, in which case the pattern can only be used for formatting (not parsing).
Since 1.2.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public ZoneLocalMappingResolver? Resolver { get; }
Property Value
| Type | Description |
|---|---|
| ZoneLocalMappingResolver | The resolver which is used to map local date/times to zoned date/times. |
TemplateValue
Gets the value used as a template for parsing: any field values unspecified
in the pattern are taken from the template.
Since 1.2.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public ZonedDateTime TemplateValue { get; }
Property Value
| Type | Description |
|---|---|
| ZonedDateTime | The value used as a template for parsing. |
TwoDigitYearMax
Maximum two-digit-year in the template to treat as the current century.
If the value parsed is higher than this, the result is adjusted to the previous century.
This value defaults to 30. To create a pattern with a different value, use WithTwoDigitYearMax(int).
Since 3.2.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public int TwoDigitYearMax { get; }
Property Value
| Type | Description |
|---|---|
| int | The value used for the maximum two-digit-year, in the range 0-99 inclusive. |
ZoneProvider
Gets the provider which is used to look up time zones when parsing a pattern
which contains a time zone identifier. This may be null, in which case the pattern can
only be used for formatting (not parsing).
Since 1.2.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public IDateTimeZoneProvider? ZoneProvider { get; }
Property Value
| Type | Description |
|---|---|
| IDateTimeZoneProvider | The provider which is used to look up time zones when parsing a pattern which contains a time zone identifier. |
Methods
AppendFormat(ZonedDateTime, StringBuilder)
Formats the given value as text according to the rules of this pattern,
appending to the given StringBuilder.
Since 2.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public StringBuilder AppendFormat(ZonedDateTime value, StringBuilder builder)
Parameters
| Type | Name | Description |
|---|---|---|
| ZonedDateTime | value | The value to format. |
| StringBuilder | builder | The StringBuilder to append to. |
Returns
| Type | Description |
|---|---|
| StringBuilder | The builder passed in as builder. |
Create(string, CultureInfo, ZoneLocalMappingResolver?, IDateTimeZoneProvider?, ZonedDateTime)
Creates a pattern for the given pattern text, culture, resolver, time zone provider, and template value.
Since 1.2.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public static ZonedDateTimePattern Create(string patternText, CultureInfo cultureInfo, ZoneLocalMappingResolver? resolver, IDateTimeZoneProvider? zoneProvider, ZonedDateTime templateValue)
Parameters
| Type | Name | Description |
|---|---|---|
| string | patternText | Pattern text to create the pattern for |
| CultureInfo | cultureInfo | The culture to use in the pattern |
| ZoneLocalMappingResolver | resolver | Resolver to apply when mapping local date/time values into the zone. |
| IDateTimeZoneProvider | zoneProvider | Time zone provider, used when parsing text which contains a time zone identifier. |
| ZonedDateTime | templateValue | Template value to use for unspecified fields |
Returns
| Type | Description |
|---|---|
| ZonedDateTimePattern | A pattern for parsing and formatting zoned date/times. |
Remarks
See the user guide for the available pattern text options.
If
zoneProvider is null, the resulting pattern can be used for formatting
but not parsing.Exceptions
| Type | Condition |
|---|---|
| InvalidPatternException | The pattern text was invalid. |
CreateWithCurrentCulture(string, IDateTimeZoneProvider?)
Creates a pattern for the given pattern text and time zone provider, using a strict resolver, the current
culture, and a default template value of midnight January 1st 2000 UTC.
Since 1.3.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public static ZonedDateTimePattern CreateWithCurrentCulture(string patternText, IDateTimeZoneProvider? zoneProvider)
Parameters
| Type | Name | Description |
|---|---|---|
| string | patternText | Pattern text to create the pattern for |
| IDateTimeZoneProvider | zoneProvider | Time zone provider, used when parsing text which contains a time zone identifier. |
Returns
| Type | Description |
|---|---|
| ZonedDateTimePattern | A pattern for parsing and formatting zoned date/times. |
Remarks
The resolver is only used if the pattern text doesn't include an offset.
If
zoneProvider is null, the resulting pattern can be used for formatting
but not parsing. Note that the current culture is captured at the time this method is called
- it is not captured at the point of parsing or formatting values.CreateWithInvariantCulture(string, IDateTimeZoneProvider?)
Creates a pattern for the given pattern text and time zone provider, using a strict resolver, the invariant
culture, and a default template value of midnight January 1st 2000 UTC.
Since 1.2.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public static ZonedDateTimePattern CreateWithInvariantCulture(string patternText, IDateTimeZoneProvider? zoneProvider)
Parameters
| Type | Name | Description |
|---|---|---|
| string | patternText | Pattern text to create the pattern for |
| IDateTimeZoneProvider | zoneProvider | Time zone provider, used when parsing text which contains a time zone identifier. |
Returns
| Type | Description |
|---|---|
| ZonedDateTimePattern | A pattern for parsing and formatting zoned date/times. |
Remarks
The resolver is only used if the pattern text doesn't include an offset.
If
zoneProvider is null, the resulting pattern can be used for formatting
but not parsing.Format(ZonedDateTime)
Formats the given zoned date/time as text according to the rules of this pattern.
Since 1.2.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public string Format(ZonedDateTime value)
Parameters
| Type | Name | Description |
|---|---|---|
| ZonedDateTime | value | The zoned date/time to format. |
Returns
| Type | Description |
|---|---|
| string | The zoned date/time formatted according to this pattern. |
Parse(string)
Parses the given text value according to the rules of this pattern.
Since 1.2.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public ParseResult<ZonedDateTime> Parse(string text)
Parameters
| Type | Name | Description |
|---|---|---|
| string | text | The text value to parse. |
Returns
| Type | Description |
|---|---|
| ParseResult<ZonedDateTime> | The result of parsing, which may be successful or unsuccessful. |
Remarks
This method never throws an exception (barring a bug in Noda Time itself). Even errors such as
the argument being null are wrapped in a parse result.
WithCalendar(CalendarSystem)
Creates a pattern like this one, but with the template value modified to use
the specified calendar system.
Since 2.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public ZonedDateTimePattern WithCalendar(CalendarSystem calendar)
Parameters
| Type | Name | Description |
|---|---|---|
| CalendarSystem | calendar | The calendar system to convert the template value into. |
Returns
| Type | Description |
|---|---|
| ZonedDateTimePattern | A new pattern with a template value in the specified calendar system. |
Remarks
Care should be taken in two (relatively rare) scenarios. Although the default template value is supported by all Noda Time calendar systems, if a pattern is created with a different template value and then this method is called with a calendar system which doesn't support that date, an exception will be thrown. Additionally, if the pattern only specifies some date fields, it's possible that the new template value will not be suitable for all values.
WithCulture(CultureInfo)
Creates a pattern for the same original pattern text as this pattern, but with the specified
culture.
Since 1.2.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public ZonedDateTimePattern WithCulture(CultureInfo cultureInfo)
Parameters
| Type | Name | Description |
|---|---|---|
| CultureInfo | cultureInfo | The culture to use in the new pattern. |
Returns
| Type | Description |
|---|---|
| ZonedDateTimePattern | A new pattern with the given culture. |
WithPatternText(string)
Creates a pattern for the same original localization information as this pattern, but with the specified
pattern text.
Since 1.2.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public ZonedDateTimePattern WithPatternText(string patternText)
Parameters
| Type | Name | Description |
|---|---|---|
| string | patternText | The pattern text to use in the new pattern. |
Returns
| Type | Description |
|---|---|
| ZonedDateTimePattern | A new pattern with the given pattern text. |
WithResolver(ZoneLocalMappingResolver?)
Creates a pattern for the same original pattern text as this pattern, but with the specified
resolver.
Since 1.2.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public ZonedDateTimePattern WithResolver(ZoneLocalMappingResolver? resolver)
Parameters
| Type | Name | Description |
|---|---|---|
| ZoneLocalMappingResolver | resolver | The new local mapping resolver to use. |
Returns
| Type | Description |
|---|---|
| ZonedDateTimePattern | A new pattern with the given resolver. |
WithTemplateValue(ZonedDateTime)
Creates a pattern like this one, but with the specified template value.
Since 1.2.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public ZonedDateTimePattern WithTemplateValue(ZonedDateTime newTemplateValue)
Parameters
| Type | Name | Description |
|---|---|---|
| ZonedDateTime | newTemplateValue | The template value for the new pattern, used to fill in unspecified fields. |
Returns
| Type | Description |
|---|---|
| ZonedDateTimePattern | A new pattern with the given template value. |
WithTwoDigitYearMax(int)
Creates a pattern like this one, but with a different TwoDigitYearMax value.
Since 3.2.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public ZonedDateTimePattern WithTwoDigitYearMax(int twoDigitYearMax)
Parameters
| Type | Name | Description |
|---|---|---|
| int | twoDigitYearMax | The value to use for TwoDigitYearMax in the new pattern, in the range 0-99 inclusive. |
Returns
| Type | Description |
|---|---|
| ZonedDateTimePattern | A new pattern with the specified maximum two-digit-year. |
WithZoneProvider(IDateTimeZoneProvider?)
Creates a pattern for the same original pattern text as this pattern, but with the specified
time zone provider.
Since 1.2.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public ZonedDateTimePattern WithZoneProvider(IDateTimeZoneProvider? newZoneProvider)
Parameters
| Type | Name | Description |
|---|---|---|
| IDateTimeZoneProvider | newZoneProvider | The new time zone provider to use. |
Returns
| Type | Description |
|---|---|
| ZonedDateTimePattern | A new pattern with the given time zone provider. |
Remarks
If
newZoneProvider is null, the resulting pattern can be used for formatting
but not parsing.