Month adjustInto() method in Java
The adjustInto() method of java.time.Month ENUM is an in-built function in Java which takes a Temporal object specifying a date and returns a new Temporal object of the same observable type as the input with the month replaced with this month-of-year.
public Temporal adjustInto(Temporal temporal)
Temporal newLocalDate = Month.ANYMONTH.adjustInto(Temporal temporal)
Parameters: This method takes temporal as parameter where:
- temporal – is the specified date to be adjusted.
- ANYMONTH – is the specified month to which the date is to be adjusted, e.g., JANUARY, FEBRUARY, etc.
- newLocalDate – is the modified date.
Return Value: The function returns an adjusted Temporal object which is the date adjusted according to specified Month.
- DateTimeException: This method throws this exception if it is not possible to make the adjustment.
- ArithmeticException: This exception is thrown if numeric overflow occurs.
Below programs illustrate the above method:
1947-08-15 which is AUGUST 1947-01-15 which is JANUARY
2019-03-18 which is MARCH 2019-12-18 which is DECEMBER
My Personal Notes arrow_drop_up
Please Login to comment...