OffsetTime adjustInto() method in Java with examples
The adjustInto() method of OffsetDateTime class in Java adjusts the specified temporal object to have the same time as this object.
public Temporal adjustInto(Temporal temporal)
Parameter : This method accepts a single parameter temporal which specifies the target object to be adjusted, not null.
Return Value: It returns the adjusted object, not null
Errors and exception : This method throws two exceptions as described below:
- DateTimeException: if unable to make the adjustment.
- ArithmeticException: if numeric overflow occurs.
Below programs illustrate the adjustInto() method:
Program 1 :
Current date:2018-12-11T10:01:37.877Z[Etc/UTC] Adjusted date:2018-12-11T14:30:30Z[Etc/UTC]
Program 2 :
Current date:2018-12-11T10:01:42.520Z[Etc/UTC] java.time.format.DateTimeParseException: Text '25:30:30+05:00' could not be parsed: Invalid value for HourOfDay (valid values 0 - 23): 25
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.