ChronoLocalDate with(TemporalField, long) Method in Java with Examples Last Updated : 29 Apr, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report with(TemporalField field, long newValue) method of the ChronoLocalDate interface used to set the specified field of ChronoLocalDate to a new value and returns the copy of new date-time.This method can be used to change any supported field, such as the year, month or day-of-month. An exception is thrown If setting the new value is not possible due to the field is not supported or for some other reason. In some cases, changing the specified field can cause the resulting date-time to become invalid, such as changing the month from 31st January to February would make the day-of-month invalid. In cases like this, the field is responsible for resolving the date. Typically it will choose the previous valid date, which would be the last valid day of February in this example. This instance of ChronoLocalDate is immutable and unaffected by this method call. Syntax: public ChronoLocalDate with(TemporalField field, long newValue) Parameters: This method accepts field which is the field to set in the result and newValue which the new value of the field in the result as parameters. Return value: This method returns a ChronoLocalDate based on this with the specified field set. Exception: This method throws following Exceptions: DateTimeException - if the adjustment cannot be made. UnsupportedTemporalTypeException - if the field is not supported. ArithmeticException - if numeric overflow occurs. Below programs illustrate the with() method: Program 1: Java // Java program to demonstrate // ChronoLocalDate.with() method import java.time.*; import java.time.temporal.*; import java.time.chrono.*; public class GFG { public static void main(String[] args) { // create a ChronoLocalDate object ChronoLocalDate local = LocalDate.parse( "2018-12-06"); // print instance System.out.println("ChronoLocalDate before" + " applying method: " + local); // apply with method of ChronoLocalDate class ChronoLocalDate updatedlocal = local.with( ChronoField.DAY_OF_MONTH, 30); // print instance System.out.println("ChronoLocalDate after" + " applying method: " + updatedlocal); } } Output: ChronoLocalDate before applying method: 2018-12-06 ChronoLocalDate after applying method: 2018-12-30 References: https://docs.oracle.com/javase/9/docs/api/java/time/chrono/ChronoLocalDate.html#with-java.time.temporal.TemporalField-long- Comment More infoAdvertise with us Next Article ChronoLocalDate minus(long, TemporalUnit) method in Java with Examples K Kirti_Mangal Follow Improve Article Tags : Java Java-Functions Java-time package Java-ChronoLocalDate Practice Tags : Java Similar Reads ChronoLocalDateTime with(TemporalField, long) method in Java with Examples The with(TemporalField field, long newValue) method of the ChronoLocalDateTime interface is used to set the specified field of ChronoLocalDateTime to a new value and returns the copy of new time. This method can be used to change any supported field, such as year, day, month, hour, minute or second. 2 min read ChronoZonedDateTime with(TemporalField, long) method in Java with Examples The with(TemporalField field, long newValue) method of the ChronoZonedDateTime interface is used to set the specified field of ChronoZonedDateTime to a new value and returns the copy of new time. This method can be used to change any supported field, such as year, day, month, hour, minute or second. 2 min read ChronoLocalDate plus(long, TemporalUnit) method in Java with Examples plus(long, TemporalUnit) method of a ChronoLocalDate interface used to return a copy of this ChronoLocalDate with the specified amount of unit added to ChronoLocalDate.If it is not possible to add the amount, because the unit is not supported or for some other reason, an exception is thrown.This ins 1 min read ChronoLocalDate with(TemporalAdjuster) Method in Java with Examples 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 Chr 1 min read ChronoLocalDate minus(long, TemporalUnit) method in Java with Examples minus(long, TemporalUnit) method of a ChronoLocalDate interface used to Returns a copy of this ChronoLocalDate with the specified amount of unit subtracted to ChronoLocalDate.If it is not possible to subtract the amount, because the unit is not supported or for some other reason, an exception is thr 2 min read ChronoLocalDateTime with(TemporalAdjuster) method in Java with Examples The with(TemporalAdjuster adjuster) method of the ChronoLocalDateTime interface is used to adjust this date-time using TemporalAdjuster and after adjustment returns the copy of adjusted date-time. The adjustment takes place using the specified adjuster strategy object. This instance of ChronoLocalDa 2 min read Like