ZonedDateTime.With Method

Definition

Overloads

Name Description
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.

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/ZonedDateTime;", "", 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/ZonedDateTime;", "", 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

a ZonedDateTime based on this with the specified field set, not null

Attributes

Remarks

Returns a copy of this date-time with the specified field set to a new value. This returns a ZonedDateTime, 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 zone and nano-of-second are unchanged. The result will have an offset derived from the new instant and original zone. If the new instant value is outside the valid range then a DateTimeException will be thrown. The OFFSET_SECONDS field will typically be ignored. The offset of a ZonedDateTime is controlled primarily by the time-zone. As such, changing the offset does not generally make sense, because there is only one valid offset for the local date-time and zone. If the zoned date-time is in a daylight savings overlap, then the offset is used to switch between the two valid offsets. In all other cases, the offset is ignored. 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. The zone is not part of the calculation and will be unchanged. When converting back to ZonedDateTime, if the local date-time is in an overlap, then the offset will be retained if possible, otherwise the earlier offset will be used. If in a gap, the local date-time will be adjusted forward by the length of the gap. 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.ZonedDateTime.with.

Applies to

With(ITemporalAdjuster)

Returns an adjusted copy of this date-time.

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

Parameters

adjuster
ITemporalAdjuster

the adjuster to use, not null

Returns

a ZonedDateTime based on this with the adjustment made, not null

Attributes

Remarks

Returns an adjusted copy of this date-time. This returns a ZonedDateTime, 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 and LocalTime implement TemporalAdjuster, thus this method can be used to change the date, time or offset: ZoneOffset also implements TemporalAdjuster however using it as an argument typically has no effect. The offset of a ZonedDateTime is controlled primarily by the time-zone. As such, changing the offset does not generally make sense, because there is only one valid offset for the local date-time and zone. If the zoned date-time is in a daylight savings overlap, then the offset is used to switch between the two valid offsets. In all other cases, the offset is ignored. 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.ZonedDateTime.with.

Applies to