次の方法で共有


DateTimeFormatter.WithChronology(IChronology) Method

Definition

Returns a copy of this formatter with a new override chronology.

[Android.Runtime.Register("withChronology", "(Ljava/time/chrono/Chronology;)Ljava/time/format/DateTimeFormatter;", "", ApiSince=26)]
public Java.Time.Format.DateTimeFormatter? WithChronology (Java.Time.Chrono.IChronology? chrono);
[<Android.Runtime.Register("withChronology", "(Ljava/time/chrono/Chronology;)Ljava/time/format/DateTimeFormatter;", "", ApiSince=26)>]
member this.WithChronology : Java.Time.Chrono.IChronology -> Java.Time.Format.DateTimeFormatter

Parameters

chrono
IChronology

the new chronology, null if no override

Returns

a formatter based on this formatter with the requested override chronology, not null

Attributes

Remarks

Returns a copy of this formatter with a new override chronology.

This returns a formatter with similar state to this formatter but with the override chronology set. By default, a formatter has no override chronology, returning null.

If an override is added, then any date that is formatted or parsed will be affected.

When formatting, if the temporal object contains a date, then it will be converted to a date in the override chronology. Whether the temporal contains a date is determined by querying the ChronoField#EPOCH_DAY EPOCH_DAY field. Any time or zone will be retained unaltered unless overridden.

If the temporal object does not contain a date, but does contain one or more ChronoField date fields, then a DateTimeException is thrown. In all other cases, the override chronology is added to the temporal, replacing any previous chronology, but without changing the date/time.

When parsing, there are two distinct cases to consider. If a chronology has been parsed directly from the text, perhaps because DateTimeFormatterBuilder#appendChronologyId() was used, then this override chronology has no effect. If no zone has been parsed, then this override chronology will be used to interpret the ChronoField values into a date according to the date resolving rules of the chronology.

This instance is immutable and unaffected by this method call.

Java documentation for java.time.format.DateTimeFormatter.withChronology(java.time.chrono.Chronology).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to