MonthDay adjustInto() method in Java with Examples

adjustInto() method of the MonthDay class used to adjusts the passed temporal object to have this MonthYear on which this method is applied.This instance is immutable and unaffected by this method call.

Syntax:

public Temporal adjustInto(Temporal temporal)

Parameters: This method accepts temporal as parameter which is the target temporal object to be adjusted. It should not be null.

Return value: This method returns the adjusted object.

Exception: This method throws following Exceptions:



  • DateTimeException – if unable to make the adjustment.
  • ArithmeticException – if unable to make the adjustment.

Below programs illustrate the adjustInto() method:
Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java program to demonstrate
// MonthDay.adjustInto() method
  
import java.time.*;
import java.time.temporal.*;
  
public class GFG {
    public static void main(String[] args)
    {
        // create a MonthDay object
        MonthDay mday = MonthDay.of(10, 31);
  
        // print instance
        System.out.println("MonthDay :"
                           + mday);
  
        // create a temporal object
        LocalDate date
 = LocalDate.parse("2007-12-03");
  
        // print instance
        System.out.println("LocalDate :"
                           + date);
  
        // apply adjustInto method of Year class
        LocalDate updatedlocal
 = (LocalDate)mday.adjustInto(date);
  
        // print instance
        System.out.println("LocalDate after"
                           + " applying adjustInto method: "
                           + updatedlocal);
    }
}

chevron_right


Output:

MonthDay :--10-31
LocalDate :2007-12-03
LocalDate after applying adjustInto method: 2007-10-31

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java program to demonstrate
// MonthDay.adjustInto() method
  
import java.time.*;
import java.time.temporal.*;
  
public class GFG {
    public static void main(String[] args)
    {
        // create a MonthDay object
        MonthDay mday = MonthDay.of(12, 22);
  
        // print instance
        System.out.println("MonthDay :"
                           + mday);
  
        // create a temporal object
        LocalDate date
 = LocalDate.parse("2017-12-03");
  
        // print instance
        System.out.println("LocalDate :"
                           + date);
  
        // apply adjustInto method of Year class
        LocalDate updatedlocal 
= (LocalDate)mday.adjustInto(date);
  
        // print instance
        System.out.println("LocalDate after"
                           + " applying adjustInto method: "
                           + updatedlocal);
    }
}

chevron_right


Output:

MonthDay :--12-22
LocalDate :2017-12-03
LocalDate after applying adjustInto method: 2017-12-22

References: https://docs.oracle.com/javase/10/docs/api/java/time/MonthDay.html#adjustInto(java.time.temporal.Temporal)



My Personal Notes arrow_drop_up

I am a Developer I love to code and bring my ideas alive

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.