Early Preview
This is currently very much a preview. Please feel free to try things out,
but don't be upset if anything is not yet working. Feedback is welcome over on our
GitHub Dicussions page.
class NodaTime.​Text.​ZonedDateTimePattern
Assembly: NodaTime
Inheritance: object → ZonedDateTimePattern
Implemented Interfaces
Represents a pattern for parsing and formatting <see cref="T:NodaTime.ZonedDateTime" /> values.
Properties
public static
ZonedDateTimePattern
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.
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 <see cref="M:NodaTime.Text.ZonedDateTimePattern.WithZoneProvider(NodaTime.IDateTimeZoneProvider)" /> on the value of this property to obtain a
pattern which can be used for parsing.
public static
ZonedDateTimePattern
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.
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 <see cref="M:NodaTime.Text.ZonedDateTimePattern.WithZoneProvider(NodaTime.IDateTimeZoneProvider)" /> on the value of this property to obtain a
pattern which can be used for parsing.
public
string
PatternText
Gets the pattern text for this pattern, as supplied on creation.
public
ZonedDateTime
TemplateValue
Gets the value used as a template for parsing: any field values unspecified
in the pattern are taken from the template.
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).
public
IDateTimeZoneProvider
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).
public
int
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 <see cref="M:NodaTime.Text.ZonedDateTimePattern.WithTwoDigitYearMax(System.Int32)" /> .
Methods
public
ParseResult<​ZonedDateTime>
Parse​(string text)
Parses the given text value according to the rules of this pattern.
Returns The result of parsing, which may be successful or unsuccessful.
text
The text value to parse.
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.
public
string
Format​(ZonedDateTime value)
Formats the given zoned date/time as text according to the rules of this pattern.
Returns The zoned date/time formatted according to this pattern.
value
The zoned date/time to format.
AppendFormat​(ZonedDateTime value,
System.​Text.​StringBuilder builder)
Formats the given value as text according to the rules of this pattern,
appending to the given <see cref="T:System.Text.StringBuilder" /> .
Returns The builder passed in as <paramref name="builder" /> .
value
The value to format.
builder
The <c>StringBuilder</c> to append to.
public static
ZonedDateTimePattern
Create​(string patternText,
System.​Globalization.​CultureInfo cultureInfo,
TimeZones.​ZoneLocalMappingResolver? resolver,
IDateTimeZoneProvider? zoneProvider,
ZonedDateTime templateValue)
Creates a pattern for the given pattern text, culture, resolver, time zone provider, and template value.
Returns A pattern for parsing and formatting zoned date/times.
patternText
Pattern text to create the pattern for
cultureInfo
The culture to use in the pattern
resolver
Resolver to apply when mapping local date/time values into the zone.
zoneProvider
Time zone provider, used when parsing text which contains a time zone identifier.
templateValue
Template value to use for unspecified fields
Remarks
See the user guide for the available pattern text options.
If <paramref name="zoneProvider" /> is null, the resulting pattern can be used for formatting
but not parsing.
public static
ZonedDateTimePattern
CreateWithInvariantCulture​(string patternText,
IDateTimeZoneProvider? zoneProvider)
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.
Returns A pattern for parsing and formatting zoned date/times.
patternText
Pattern text to create the pattern for
zoneProvider
Time zone provider, used when parsing text which contains a time zone identifier.
Remarks
The resolver is only used if the pattern text doesn't include an offset.
If <paramref name="zoneProvider" /> is null, the resulting pattern can be used for formatting
but not parsing.
public static
ZonedDateTimePattern
CreateWithCurrentCulture​(string patternText,
IDateTimeZoneProvider? zoneProvider)
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.
Returns A pattern for parsing and formatting zoned date/times.
patternText
Pattern text to create the pattern for
zoneProvider
Time zone provider, used when parsing text which contains a time zone identifier.
Remarks
The resolver is only used if the pattern text doesn't include an offset.
If <paramref name="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.
public
ZonedDateTimePattern
WithPatternText​(string patternText)
Creates a pattern for the same original localization information as this pattern, but with the specified
pattern text.
Returns A new pattern with the given pattern text.
patternText
The pattern text to use in the new pattern.
public
ZonedDateTimePattern
WithCulture​(System.​Globalization.​CultureInfo cultureInfo)
Creates a pattern for the same original pattern text as this pattern, but with the specified
culture.
Returns A new pattern with the given culture.
cultureInfo
The culture to use in the new pattern.
public
ZonedDateTimePattern
WithResolver​(TimeZones.​ZoneLocalMappingResolver? resolver)
Creates a pattern for the same original pattern text as this pattern, but with the specified
resolver.
Returns A new pattern with the given resolver.
resolver
The new local mapping resolver to use.
public
ZonedDateTimePattern
WithZoneProvider​(IDateTimeZoneProvider? newZoneProvider)
Creates a pattern for the same original pattern text as this pattern, but with the specified
time zone provider.
Returns A new pattern with the given time zone provider.
newZoneProvider
The new time zone provider to use.
Remarks
If <paramref name="newZoneProvider" /> is null, the resulting pattern can be used for formatting
but not parsing.
public
ZonedDateTimePattern
WithTemplateValue​(ZonedDateTime newTemplateValue)
Creates a pattern like this one, but with the specified template value.
Returns A new pattern with the given template value.
newTemplateValue
The template value for the new pattern, used to fill in unspecified fields.
public
ZonedDateTimePattern
WithCalendar​(CalendarSystem calendar)
Creates a pattern like this one, but with the template value modified to use
the specified calendar system.
Returns A new pattern with a template value in the specified calendar system.
calendar
The calendar system to convert the template value into.
Remarks
<para>
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.
</para>
public
ZonedDateTimePattern
WithTwoDigitYearMax​(int twoDigitYearMax)
Creates a pattern like this one, but with a different <see cref="P:NodaTime.Text.ZonedDateTimePattern.TwoDigitYearMax" /> value.
Returns A new pattern with the specified maximum two-digit-year.
twoDigitYearMax
The value to use for <see cref="P:NodaTime.Text.ZonedDateTimePattern.TwoDigitYearMax" /> in the new pattern, in the range 0-99 inclusive.
public
bool
Equals​(object obj)
Inherited from object
protected
void
Finalize​()
Inherited from object
public
int
GetHashCode​()
Inherited from object
protected
object
MemberwiseClone​()
Inherited from object
public
string
ToString​()
Inherited from object