Class ZonedDateTimePattern
Represents a pattern for parsing and formatting ZonedDateTime values.
Since 3.1.x
Availability net45, netstandard1.3, netstandard2.0
Inheritance
Object
ZonedDateTimePattern
Implements
Inherited Members
Object.ToString()
Object.Equals(Object)
Object.Equals(Object, Object)
Object.ReferenceEquals(Object, Object)
Object.GetHashCode()
Object.GetType()
Object.MemberwiseClone()
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 3.1.x
Availability net45, netstandard1.3, 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. (The value returned is never null.) |
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 3.1.x
Availability net45, netstandard1.3, 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. (The value returned is never null.) |
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 3.1.x
Availability net45, netstandard1.3, netstandard2.0
Declaration
public string PatternText { get; }
Property Value
Type | Description |
---|---|
String | The pattern text for this pattern, as supplied on creation. (The value returned is never null.) |
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 3.1.x
Availability net45, netstandard1.3, 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 3.1.x
Availability net45, netstandard1.3, netstandard2.0
Declaration
public ZonedDateTime TemplateValue { get; }
Property Value
Type | Description |
---|---|
ZonedDateTime | The value used as a template for parsing. |
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 3.1.x
Availability net45, netstandard1.3, 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 System.Text.StringBuilder.
Since 3.1.x
Availability net45, netstandard1.3, 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 . (The value returned is never null.) |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | builder is null. |
Create(String, CultureInfo, ZoneLocalMappingResolver, IDateTimeZoneProvider, ZonedDateTime)
Creates a pattern for the given pattern text, culture, resolver, time zone provider, and template value.
Since 3.1.x
Availability net45, netstandard1.3, 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. (The value returned is never null.) |
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. |
ArgumentNullException | patternText or cultureInfo is null |
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 3.1.x
Availability net45, netstandard1.3, 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. (The value returned is never null.) |
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.
Exceptions
Type | Condition |
---|---|
ArgumentNullException | patternText is null. |
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 3.1.x
Availability net45, netstandard1.3, 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. (The value returned is never null.) |
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.
Exceptions
Type | Condition |
---|---|
ArgumentNullException | patternText is null. |
Format(ZonedDateTime)
Formats the given zoned date/time as text according to the rules of this pattern.
Since 3.1.x
Availability net45, netstandard1.3, 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. (The value returned is never null.) |
Parse(String)
Parses the given text value according to the rules of this pattern.
Since 3.1.x
Availability net45, netstandard1.3, 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. (The value returned is never null.) |
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 3.1.x
Availability net45, netstandard1.3, 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. (The value returned is never null.) |
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.
Exceptions
Type | Condition |
---|---|
ArgumentNullException | calendar is null. |
WithCulture(CultureInfo)
Creates a pattern for the same original pattern text as this pattern, but with the specified
culture.
Since 3.1.x
Availability net45, netstandard1.3, 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. (The value returned is never null.) |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | cultureInfo is null. |
WithPatternText(String)
Creates a pattern for the same original localization information as this pattern, but with the specified
pattern text.
Since 3.1.x
Availability net45, netstandard1.3, 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. (The value returned is never null.) |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | patternText is null. |
WithResolver(ZoneLocalMappingResolver)
Creates a pattern for the same original pattern text as this pattern, but with the specified
resolver.
Since 3.1.x
Availability net45, netstandard1.3, 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. (The value returned is never null.) |
WithTemplateValue(ZonedDateTime)
Creates a pattern like this one, but with the specified template value.
Since 3.1.x
Availability net45, netstandard1.3, 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. (The value returned is never null.) |
WithZoneProvider(IDateTimeZoneProvider)
Creates a pattern for the same original pattern text as this pattern, but with the specified
time zone provider.
Since 3.1.x
Availability net45, netstandard1.3, 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. (The value returned is never null.) |
Remarks
If
newZoneProvider
is null, the resulting pattern can be used for formatting
but not parsing.