ChronoLocalDateTime adjustInto() method in Java with Examples
The adjustInto() method of ChronoLocalDateTime interface in Java is used to adjusts the specified temporal object to have the same date as this object.
default Temporal adjustInto(Temporal temporal)
Parameter: This method accepts a single parameter temporal which is the target object to be adjusted, and not specifically null.
Return Value: It returns the adjusted object, not null.
Exceptions: The function throws two exceptions as described below:
- DateTimeException: the program throws this if it is unable to make the adjustment.
- ArithmeticException: the program throws this if there is a numeric overflow.
Below programs illustrate the adjustInto() method of ChronoLocalDateTime in Java:
Program 2: To illustrate Exception. The below program throws an exception as February is of 28 days and not 31 days.
2018-12-06T19:21:12 java.time.format.DateTimeParseException: Text '2015-02-31' could not be parsed at index 10
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.