OffsetDateTime.With Method

Definition

Overloads

Name Description
With(ITemporalAdjuster)

Returns an adjusted copy of this date-time.

With(ITemporalField, Int64)

Returns a copy of this date-time with the specified field set to a new value.

With(ITemporalAdjuster)

Returns an adjusted copy of this date-time.

[Android.Runtime.Register("with", "(Ljava/time/temporal/TemporalAdjuster;)Ljava/time/OffsetDateTime;", "", ApiSince=26)]
public Java.Time.OffsetDateTime? With(Java.Time.Temporal.ITemporalAdjuster? adjuster);
[<Android.Runtime.Register("with", "(Ljava/time/temporal/TemporalAdjuster;)Ljava/time/OffsetDateTime;", "", ApiSince=26)>]
member this.With : Java.Time.Temporal.ITemporalAdjuster -> Java.Time.OffsetDateTime

Parameters

adjuster
ITemporalAdjuster

the adjuster to use, not null

Returns

an OffsetDateTime based on this with the adjustment made, not null

Attributes

Remarks

Returns an adjusted copy of this date-time. This returns an OffsetDateTime, based on this one, with the date-time adjusted. The adjustment takes place using the specified adjuster strategy object. Read the documentation of the adjuster to understand what adjustment will be made. A simple adjuster might simply set the one of the fields, such as the year field. A more complex adjuster might set the date to the last day of the month. A selection of common adjustments is provided in TemporalAdjusters. These include finding the "last day of the month" and "next Wednesday". Key date-time classes also implement the TemporalAdjuster interface, such as Month and MonthDay. The adjuster is responsible for handling special cases, such as the varying lengths of month and leap years. For example this code returns a date on the last day of July: The classes LocalDate, LocalTime and ZoneOffset implement TemporalAdjuster, thus this method can be used to change the date, time or offset: The result of this method is obtained by invoking the TemporalAdjuster.adjustInto(Temporal) method on the specified adjuster passing this as the argument. This instance is immutable and unaffected by this method call.

Java reference for java.time.OffsetDateTime.with.

Applies to

With(ITemporalField, Int64)

Returns a copy of this date-time with the specified field set to a new value.

[Android.Runtime.Register("with", "(Ljava/time/temporal/TemporalField;J)Ljava/time/OffsetDateTime;", "", ApiSince=26)]
public Java.Time.Temporal.ITemporal? With(Java.Time.Temporal.ITemporalField? field, long newValue);
[<Android.Runtime.Register("with", "(Ljava/time/temporal/TemporalField;J)Ljava/time/OffsetDateTime;", "", ApiSince=26)>]
abstract member With : Java.Time.Temporal.ITemporalField * int64 -> Java.Time.Temporal.ITemporal
override this.With : Java.Time.Temporal.ITemporalField * int64 -> Java.Time.Temporal.ITemporal

Parameters

field
ITemporalField

the field to set in the result, not null

newValue
Int64

the new value of the field in the result

Returns

an OffsetDateTime based on this with the specified field set, not null

Implements

Attributes

Remarks

Returns a copy of this date-time with the specified field set to a new value. This returns an OffsetDateTime, based on this one, with the value for the specified field changed. This can be used to change any supported field, such as the year, month or day-of-month. If it is not possible to set the value, because the field is not supported or for some other reason, an exception is thrown. In some cases, changing the specified field can cause the resulting date-time to become invalid, such as changing the month from 31st January to February would make the day-of-month invalid. In cases like this, the field is responsible for resolving the date. Typically it will choose the previous valid date, which would be the last valid day of February in this example. If the field is a ChronoField then the adjustment is implemented here. The INSTANT_SECONDS field will return a date-time with the specified instant. The offset and nano-of-second are unchanged. If the new instant value is outside the valid range then a DateTimeException will be thrown. The OFFSET_SECONDS field will return a date-time with the specified offset. The local date-time is unaltered. If the new offset value is outside the valid range then a DateTimeException will be thrown. The other supported fields will behave as per the matching method on LocalDateTime. In this case, the offset is not part of the calculation and will be unchanged. All other ChronoField instances will throw an UnsupportedTemporalTypeException. If the field is not a ChronoField, then the result of this method is obtained by invoking TemporalField.adjustInto(Temporal, long) passing this as the argument. In this case, the field determines whether and how to adjust the instant. This instance is immutable and unaffected by this method call.

Java reference for java.time.OffsetDateTime.with.

Applies to