Class LocalTimePattern
Represents a pattern for parsing and formatting LocalTime values.
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Inherited Members
Namespace: NodaTime.Text
Assembly: NodaTime.dll
Syntax
public sealed class LocalTimePattern : IPattern<LocalTime>
Properties
ExtendedIso
Gets an invariant local time pattern which is ISO-8601 compatible, providing up to 9 decimal places.
(These digits are omitted when unnecessary.)
This corresponds to the text pattern "HH':'mm':'ss;FFFFFFFFF".
Since 1.4.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public static LocalTimePattern ExtendedIso { get; }
Property Value
Type | Description |
---|---|
LocalTimePattern | An invariant local time pattern which is ISO-8601 compatible, providing up to 9 decimal places. |
Remarks
This pattern corresponds to the 'o' standard pattern.
GeneralIso
Gets an invariant local time pattern which is ISO-8601 compatible, with precision of just seconds.
This corresponds to the text pattern "HH':'mm':'ss".
Since 3.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public static LocalTimePattern GeneralIso { get; }
Property Value
Type | Description |
---|---|
LocalTimePattern | An invariant local time pattern which is ISO-8601 compatible, with no sub-second precision. |
HourIso
Gets an invariant local time pattern which is ISO-8601 compatible, with a precision of just hours.
This corresponds to the text pattern "HH".
Since 3.2.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public static LocalTimePattern HourIso { get; }
Property Value
Type | Description |
---|---|
LocalTimePattern | An invariant local time pattern which is ISO-8601 compatible, with no sub-hour precision. |
HourMinuteIso
Gets an invariant local time pattern which is ISO-8601 compatible, with precision of just minutes.
This corresponds to the text pattern "HH':'mm".
Since 3.2.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public static LocalTimePattern HourMinuteIso { get; }
Property Value
Type | Description |
---|---|
LocalTimePattern | An invariant local time pattern which is ISO-8601 compatible, with no sub-minute precision. |
LongExtendedIso
Gets an invariant local time pattern which is ISO-8601 compatible, providing exactly 9 decimal places.
This corresponds to the text pattern "HH':'mm':'ss;fffffffff".
Since 3.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public static LocalTimePattern LongExtendedIso { get; }
Property Value
Type | Description |
---|---|
LocalTimePattern | An invariant local time pattern which is ISO-8601 compatible, providing exactly 9 decimal places. |
Remarks
This pattern corresponds to the 'O' standard pattern.
PatternText
Gets the pattern text for this pattern, as supplied on creation.
Since 1.0.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. |
TemplateValue
Gets the value used as a template for parsing: any field values unspecified
in the pattern are taken from the template.
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public LocalTime TemplateValue { get; }
Property Value
Type | Description |
---|---|
LocalTime | The value used as a template for parsing. |
VariablePrecisionIso
Gets an invariant local time pattern which can parse any ISO-8601 compatible value
(in extended format, that is, with separators), regardless of precision.
Valid values include "just hours", "hours and minutes", "hours, minutes and seconds",
and values with fractions of seconds (as far as nanoseconds).
Since 3.2.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public static IPattern<LocalTime> VariablePrecisionIso { get; }
Property Value
Type | Description |
---|---|
IPattern<LocalTime> | An invariant local time pattern which is ISO-8601 compatible for all precisions. |
Remarks
This is expressed as an IPattern<T> rather than a LocalTimePattern,
as it has no single pattern text.
Methods
AppendFormat(LocalTime, 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(LocalTime value, StringBuilder builder)
Parameters
Type | Name | Description |
---|---|---|
LocalTime | 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, with a template value of midnight.
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public static LocalTimePattern 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 |
---|---|
LocalTimePattern | A pattern for parsing and formatting local times. |
Remarks
See the user guide for the available pattern text options.
Exceptions
Type | Condition |
---|---|
InvalidPatternException | The pattern text was invalid. |
Create(string, CultureInfo, LocalTime)
Creates a pattern for the given pattern text, culture, and template value.
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public static LocalTimePattern Create(string patternText, CultureInfo cultureInfo, LocalTime templateValue)
Parameters
Type | Name | Description |
---|---|---|
string | patternText | Pattern text to create the pattern for |
CultureInfo | cultureInfo | The culture to use in the pattern |
LocalTime | templateValue | Template value to use for unspecified fields |
Returns
Type | Description |
---|---|
LocalTimePattern | A pattern for parsing and formatting local times. |
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, net8.0, netstandard2.0
Declaration
public static LocalTimePattern CreateWithCurrentCulture(string patternText)
Parameters
Type | Name | Description |
---|---|---|
string | patternText | Pattern text to create the pattern for |
Returns
Type | Description |
---|---|
LocalTimePattern | A pattern for parsing and formatting local times. |
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, net8.0, netstandard2.0
Declaration
public static LocalTimePattern CreateWithInvariantCulture(string patternText)
Parameters
Type | Name | Description |
---|---|---|
string | patternText | Pattern text to create the pattern for |
Returns
Type | Description |
---|---|
LocalTimePattern | A pattern for parsing and formatting local times. |
Remarks
See the user guide for the available pattern text options.
Exceptions
Type | Condition |
---|---|
InvalidPatternException | The pattern text was invalid. |
Format(LocalTime)
Formats the given local time as text according to the rules of this pattern.
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public string Format(LocalTime value)
Parameters
Type | Name | Description |
---|---|---|
LocalTime | value | The local time to format. |
Returns
Type | Description |
---|---|
string | The local time 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, net8.0, netstandard2.0
Declaration
public ParseResult<LocalTime> Parse(string text)
Parameters
Type | Name | Description |
---|---|---|
string | text | The text value to parse. |
Returns
Type | Description |
---|---|
ParseResult<LocalTime> | 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, net8.0, netstandard2.0
Declaration
public LocalTimePattern WithCulture(CultureInfo cultureInfo)
Parameters
Type | Name | Description |
---|---|---|
CultureInfo | cultureInfo | The culture to use in the new pattern. |
Returns
Type | Description |
---|---|
LocalTimePattern | A new pattern with the given culture. |
WithTemplateValue(LocalTime)
Creates a pattern like this one, but with the specified template value.
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
public LocalTimePattern WithTemplateValue(LocalTime newTemplateValue)
Parameters
Type | Name | Description |
---|---|---|
LocalTime | newTemplateValue | The template value for the new pattern, used to fill in unspecified fields. |
Returns
Type | Description |
---|---|
LocalTimePattern | A new pattern with the given template value. |