ChronoLocalDate with(TemporalAdjuster) Method in Java with Examples
Last Updated :
29 Apr, 2019
with(TemporalAdjuster adjuster) method of the ChronoLocalDate interface used to adjusted this date-time using TemporalAdjuster passed as parameter and after adjustment returns the copy of adjusted date-time.The adjustment takes place using the specified adjuster strategy object. This instance of ChronoLocalDate is immutable and unaffected by this method call.
Syntax:
public ChronoLocalDate with(TemporalAdjuster adjuster)
Parameters: This method accepts adjuster as parameter which is the adjuster to use.
Return value: This method returns a ChronoLocalDate based on this with the adjustment made.
Exception: This method throws following Exceptions:
- DateTimeException – if the adjustment cannot be made.
- ArithmeticException – if numeric overflow occurs.
Below programs illustrate the with() method:
Program 1:
import java.time.*;
import java.time.temporal.*;
import java.time.chrono.*;
public class GFG {
public static void main(String[] args)
{
ChronoLocalDate local
= LocalDate.parse(
"2018-12-06" );
System.out.println( "ChronoLocalDate before"
+ " adjustment: "
+ local);
ChronoLocalDate updatedlocal
= local.with(Month.MARCH)
.with(TemporalAdjusters
.lastDayOfMonth());
System.out.println( "ChronoLocalDate after"
+ " adjustment: "
+ updatedlocal);
}
}
|
Output:
ChronoLocalDate before adjustment: 2018-12-06
ChronoLocalDate after adjustment: 2018-03-31
Reference: https://docs.oracle.com/javase/9/docs/api/java/time/chrono/ChronoLocalDate.html#with-java.time.temporal.TemporalAdjuster-
Share your thoughts in the comments
Please Login to comment...