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.​LocalDateTimePattern
Assembly: NodaTime
Inheritance: object → LocalDateTimePattern
Implemented Interfaces
Represents a pattern for parsing and formatting <see cref="T:NodaTime.LocalDateTime" /> values.
Properties
public static
LocalDateTimePattern
GeneralIso
Gets an invariant local date/time pattern which is ISO-8601 compatible, down to the second.
This corresponds to the text pattern "uuuu'-'MM'-'dd'T'HH':'mm':'ss".
Remarks This pattern corresponds to the 's' standard pattern ("shorter sortable").
public static
LocalDateTimePattern
ExtendedIso
Gets an invariant local date/time 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".
Remarks This pattern corresponds to the 'S' standard pattern ("longer sortable").
public static
LocalDateTimePattern
BclRoundtrip
Gets an invariant local date/time pattern which is ISO-8601 compatible, providing up to 7 decimal places
of sub-second accuracy which are always present (including trailing zeroes). This is compatible with the
BCL round-trip formatting of <see cref="T:System.DateTime" /> values with a kind of "unspecified".
This corresponds to the text pattern "uuuu'-'MM'-'dd'T'HH':'mm':'ss'.'fffffff". It does not necessarily
round-trip all <c>LocalDateTime</c> values as it will lose sub-tick information. Use
<see cref="P:NodaTime.Text.LocalDateTimePattern.FullRoundtripWithoutCalendar" /> for full precision.
Remarks This pattern corresponds to the 'o' and 'O' standard patterns.
public static
LocalDateTimePattern
FullRoundtripWithoutCalendar
Gets an invariant local date/time pattern which round trips values, but doesn't include the calendar system.
It provides up to 9 decimal places of sub-second accuracy which are always present (including trailing zeroes).
This corresponds to the text pattern "uuuu'-'MM'-'dd'T'HH':'mm':'ss'.'fffffffff". It will
round-trip all <see cref="T:NodaTime.LocalDateTime" /> values if the calendar system of the template value is the same
as the calendar system of the original value.
Remarks This pattern corresponds to the 'r' standard pattern.
public static
LocalDateTimePattern
FullRoundtrip
Gets an invariant local date/time pattern which round trips values including the calendar system.
This corresponds to the text pattern "uuuu'-'MM'-'dd'T'HH':'mm':'ss'.'fffffffff '('c')'".
Remarks This pattern corresponds to the 'R' standard pattern.
public static
LocalDateTimePattern
DateHourMinuteIso
Gets an invariant local date/time pattern which is ISO-8601 compatible, with precision of just minutes.
This corresponds to the text pattern "uuuu'-'MM'-'dd'T'HH':'mm".
public static
LocalDateTimePattern
DateHourIso
Gets an invariant local date/time pattern which is ISO-8601 compatible, with a precision of just hours.
This corresponds to the text pattern "uuuu'-'MM'-'dd'T'HH".
public static
IPattern<​LocalDateTime>
VariablePrecisionIso
Gets an invariant local date/time pattern which can parse any ISO-8601 compatible value with a calendar date
(in extended format, that is, with separators), regardless of precision in the time part.
Valid values for time include "just hours", "hours and minutes", "hours, minutes and seconds",
and values with fractions of seconds (as far as nanoseconds). The time part must be present, however; this pattern
will not parse date-only values. (It will also not parse ordinal dates or week dates, as described in ISO-8601.)
Remarks This is expressed as an <see cref="T:NodaTime.Text.IPattern`1" /> rather than a <see cref="T:NodaTime.Text.LocalDateTimePattern" /> ,
as it has no single pattern text.
public
string
PatternText
Gets the pattern text for this pattern, as supplied on creation.
public
LocalDateTime
TemplateValue
Get the value used as a template for parsing: any field values unspecified
in the pattern are taken from the template.
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.LocalDateTimePattern.WithTwoDigitYearMax(System.Int32)" /> .
Methods
public
ParseResult<​LocalDateTime>
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​(LocalDateTime value)
Formats the given local date/time as text according to the rules of this pattern.
Returns The local date/time formatted according to this pattern.
value
The local date/time to format.
AppendFormat​(LocalDateTime 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
LocalDateTimePattern
Create​(string patternText,
System.​Globalization.​CultureInfo cultureInfo,
LocalDateTime templateValue)
Creates a pattern for the given pattern text, culture, and template value.
Returns A pattern for parsing and formatting local date/times.
patternText
Pattern text to create the pattern for
cultureInfo
The culture to use in the pattern
templateValue
Template value to use for unspecified fields
Remarks
See the user guide for the available pattern text options.
public static
LocalDateTimePattern
Create​(string patternText,
System.​Globalization.​CultureInfo cultureInfo)
Creates a pattern for the given pattern text and culture, with a template value of midnight on 2000-01-01.
Returns A pattern for parsing and formatting local date/times.
patternText
Pattern text to create the pattern for
cultureInfo
The culture to use in the pattern
Remarks
See the user guide for the available pattern text options.
public static
LocalDateTimePattern
CreateWithCurrentCulture​(string patternText)
Creates a pattern for the given pattern text in the current thread's current culture.
Returns A pattern for parsing and formatting local date/times.
patternText
Pattern text to create the pattern for
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.
public static
LocalDateTimePattern
CreateWithInvariantCulture​(string patternText)
Creates a pattern for the given pattern text in the invariant culture.
Returns A pattern for parsing and formatting local date/times.
patternText
Pattern text to create the pattern for
Remarks
See the user guide for the available pattern text options.
public
LocalDateTimePattern
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
LocalDateTimePattern
WithTemplateValue​(LocalDateTime 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
LocalDateTimePattern
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
LocalDateTimePattern
WithTwoDigitYearMax​(int twoDigitYearMax)
Creates a pattern like this one, but with a different <see cref="P:NodaTime.Text.LocalDateTimePattern.TwoDigitYearMax" /> value.
Returns A new pattern with the specified maximum two-digit-year.
twoDigitYearMax
The value to use for <see cref="P:NodaTime.Text.LocalDateTimePattern.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