The adjustInto() method of ChronoLocalDate interface in Java is used to adjusts the specified temporal object to have the same date as this object.
Syntax:
public 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 ChronoLocalDate in Java:
Program 1:
// Program to illustrate the adjustInto() method import java.util.*; import java.time.*; import java.time.chrono.*; public class GfG { public static void main(String[] args) { ZonedDateTime date = ZonedDateTime.now(); // prints the date System.out.println(date); // Parses the date ChronoLocalDate date1 = LocalDate.parse("2015-01-31"); // Uses the function to adjust the date date = (ZonedDateTime)date1.adjustInto(date); // Prints the adjusted date System.out.println(date); } } |
2019-04-28T19:58:13.775Z[Etc/UTC] 2015-01-31T19:58:13.775Z[Etc/UTC]
Program 2: To illustrate Exception. The below program throws an exception as February is of 28 days and not 31 days.
// Program to illustrate the adjustInto() method // Exception Program import java.util.*; import java.time.*; import java.time.chrono.*; public class GfG { public static void main(String[] args) { try { ZonedDateTime date = ZonedDateTime.now(); // prints the date System.out.println(date); // Parses the date ChronoLocalDate date1 = LocalDate.parse("2015-02-31"); // Uses the function to adjust the date date = (ZonedDateTime)date1.adjustInto(date); // Prints the adjusted date System.out.println(date); } catch (Exception e) { System.out.println(e); } } } |
2019-04-28T19:58:17.219Z[Etc/UTC] java.time.format.DateTimeParseException: Text '2015-02-31' could not be parsed: Invalid date 'FEBRUARY 31'
Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
Recommended Posts:
- ChronoLocalDate until(ChronoLocalDate) Method in Java with Examples
- Year adjustInto() Method in Java with Examples
- LocalTime adjustInto() method in Java with Examples
- ZoneOffset adjustInto(Temporal) method in Java with Examples
- OffsetDateTime adjustInto() method in Java with examples
- OffsetTime adjustInto() method in Java with examples
- MonthDay adjustInto() method in Java with Examples
- DayOfWeek adjustInto() method in Java with Examples
- ChronoLocalDateTime adjustInto() method in Java with Examples
- Instant adjustInto() method in Java with Example
- LocalDate adjustInto() method in Java
- Month adjustInto() method in Java
- LocalDate until(ChronoLocalDate) Method in Java with Examples
- ChronoLocalDate minus(TemporalAmount) method in Java with Examples
- ChronoLocalDate until(Temporal,TemporalUnit) Method in Java with Examples
- ChronoLocalDate hashCode() method in Java with Examples
- ChronoLocalDate plus(TemporalAmount) method in Java with Examples
- ChronoLocalDate toEpochDay() method in Java with Examples
- ChronoLocalDate isBefore() method in Java with Examples
- ChronoLocalDate range() method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

