Java Instant adjustInto() method

The adjustInto() method of Java Instant class is used to adjust the specified Temporal(Interface) object which have this instant.

This method returns a temporal object of the same observable type as the input with the instant changed to be the same as this.

Syntax

Parameters

temporal - The target object to be adjusted, not null

Return

The adjusted object, not null

The adjustment is equivalent to using Temporal.with(TemporalField, long) twice,passing ChronoField.INSTANT_SECONDS and ChronoField.NANO_OF_SECOND as the fields.

In most cases, it is clearer to reverse the calling pattArn by using Temporal.with(TemporalAdjuster):

Exceptions

DateTimeException - If unable to make the adjustment

ArithmeticException - If numeric overflow occurs

Example 1

Output:

The output will be like this.
2014-12-03T10:15:30Z[Asia/New_Delhi]

Example 2

Output:

2017-03-10T11:10:35.454+05:30[Asia/Calcutta]
2017-02-03T16:07:30+05:30[Asia/Calcutta]

Example 3

Output:

2017-04-09T10:15:30Z
 OffsetDateTime > 2017-05-01T15:50:28.538-05:00 > 2017-04-09T05:15:30-05:00
  ZonedDateTime > 2017-05-01T15:50:28.540-05:00[Asia/New_Delhi] > 2017-04-09T05:15:30-05:00[Asia/New_Delhi]
        Instant > 2017-05-01T20:50:28.540Z > 2017-04-09T10:15:30Z