Class InstantPattern
Represents a pattern for parsing and formatting Instant values.
Since 1.0.x
Availability net6.0, netstandard2.0
Inheritance
Object
InstantPattern
Inherited Members
Object.Equals(Object)
Object.Equals(Object, Object)
Object.GetHashCode()
Object.GetType()
Object.MemberwiseClone()
Object.ReferenceEquals(Object, Object)
Object.ToString()
Namespace: NodaTime.Text
Assembly: NodaTime.dll
Syntax
public sealed class InstantPattern : IPattern<Instant>
Properties
ExtendedIso
Gets an invariant instant pattern which is ISO-8601 compatible, providing up to 9 decimal places
of sub-second accuracy. (These digits are omitted when unnecessary.)
This corresponds to the text pattern "uuuu'-'MM'-'dd'T'HH':'mm':'ss;FFFFFFFFF'Z'".
Since 1.4.x
Availability net6.0, netstandard2.0
Declaration
public static InstantPattern ExtendedIso { get; }
Property Value
Type | Description |
---|---|
InstantPattern | An invariant instant pattern which is ISO-8601 compatible, providing up to 9 decimal places of sub-second accuracy. |
General
Gets the general pattern, which always uses an invariant culture. The general pattern represents
an instant as a UTC date/time in ISO-8601 style "uuuu-MM-ddTHH:mm:ss'Z'".
Since 1.4.x
Availability net6.0, netstandard2.0
Declaration
public static InstantPattern General { get; }
Property Value
Type | Description |
---|---|
InstantPattern | The general pattern, which always uses an invariant culture. |
PatternText
Gets the pattern text for this pattern, as supplied on creation.
Since 1.0.x
Availability net6.0, netstandard2.0
Declaration
public string PatternText { get; }
Property Value
Type | Description |
---|---|
String | The pattern text for this pattern, as supplied on creation. |
TemplateValue
Gets the value used as a template for parsing: any field values unspecified
in the pattern are taken from the template.
Since 3.0.x
Availability net6.0, netstandard2.0
Declaration
public Instant TemplateValue { get; }
Property Value
Type | Description |
---|---|
Instant | The value used as a template for parsing. |
Methods
AppendFormat(Instant, StringBuilder)
Formats the given value as text according to the rules of this pattern,
appending to the given System.Text.StringBuilder.
Since 2.0.x
Availability net6.0, netstandard2.0
Declaration
public StringBuilder AppendFormat(Instant value, StringBuilder builder)
Parameters
Type | Name | Description |
---|---|---|
Instant | 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)
Creates a pattern for the given pattern text and culture.
Since 1.0.x
Availability net6.0, netstandard2.0
Declaration
public static InstantPattern Create(string patternText, CultureInfo cultureInfo)
Parameters
Type | Name | Description |
---|---|---|
String | patternText | Pattern text to create the pattern for |
CultureInfo | cultureInfo | The culture to use in the pattern |
Returns
Type | Description |
---|---|
InstantPattern | A pattern for parsing and formatting instants. |
Remarks
See the user guide for the available pattern text options.
Exceptions
Type | Condition |
---|---|
InvalidPatternException | The pattern text was invalid. |
CreateWithCurrentCulture(String)
Creates a pattern for the given pattern text in the current thread's current culture.
Since 1.0.x
Availability net6.0, netstandard2.0
Declaration
public static InstantPattern CreateWithCurrentCulture(string patternText)
Parameters
Type | Name | Description |
---|---|---|
String | patternText | Pattern text to create the pattern for |
Returns
Type | Description |
---|---|
InstantPattern | A pattern for parsing and formatting instants. |
Remarks
See the user guide for the available pattern text options. 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 |
---|---|
InvalidPatternException | The pattern text was invalid. |
CreateWithInvariantCulture(String)
Creates a pattern for the given pattern text in the invariant culture.
Since 1.0.x
Availability net6.0, netstandard2.0
Declaration
public static InstantPattern CreateWithInvariantCulture(string patternText)
Parameters
Type | Name | Description |
---|---|---|
String | patternText | Pattern text to create the pattern for |
Returns
Type | Description |
---|---|
InstantPattern | A pattern for parsing and formatting instants. |
Remarks
See the user guide for the available pattern text options.
Exceptions
Type | Condition |
---|---|
InvalidPatternException | The pattern text was invalid. |
Format(Instant)
Formats the given instant as text according to the rules of this pattern.
Since 1.0.x
Availability net6.0, netstandard2.0
Declaration
public string Format(Instant value)
Parameters
Type | Name | Description |
---|---|---|
Instant | value | The instant to format. |
Returns
Type | Description |
---|---|
String | The instant formatted according to this pattern. |
Parse(String)
Parses the given text value according to the rules of this pattern.
Since 1.0.x
Availability net6.0, netstandard2.0
Declaration
public ParseResult<Instant> Parse(string text)
Parameters
Type | Name | Description |
---|---|---|
String | text | The text value to parse. |
Returns
Type | Description |
---|---|
ParseResult<Instant> | 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.
WithCulture(CultureInfo)
Creates a pattern for the same original pattern text as this pattern, but with the specified
culture.
Since 1.0.x
Availability net6.0, netstandard2.0
Declaration
public InstantPattern WithCulture(CultureInfo cultureInfo)
Parameters
Type | Name | Description |
---|---|---|
CultureInfo | cultureInfo | The culture to use in the new pattern. |
Returns
Type | Description |
---|---|
InstantPattern | A new pattern with the given culture. |
WithTemplateValue(Instant)
Creates a pattern like this one, but with the specified template value.
Since 3.0.x
Availability net6.0, netstandard2.0
Declaration
public InstantPattern WithTemplateValue(Instant newTemplateValue)
Parameters
Type | Name | Description |
---|---|---|
Instant | newTemplateValue | The template value for the new pattern, used to fill in unspecified fields. |
Returns
Type | Description |
---|---|
InstantPattern | A new pattern with the given template value. |