MonthDay with() Method in Java with Examples Last Updated : 15 Jan, 2019 Comments Improve Suggest changes Like Article Like Report with(Month month) method of the MonthDay class used to alter the month-of-year of MonthDay object using month passed as a parameter and after that method returns the copy of altered MonthDay.If the day-of-month value is invalid for the specified month after altering operation, the day will be adjusted to the last valid day-of-month. Syntax: public MonthDay with(Month month) Parameters: This method accepts month as parameter which is the month-of-year to set in the returned month-day. Return value: This method returns a MonthDay based on this month-day with the requested month Below programs illustrate the with() method: Program 1: Java // Java program to demonstrate // MonthDay.with() method import java.time.*; import java.time.temporal.*; public class GFG { public static void main(String[] args) { // create a MonthDay object MonthDay monthday = MonthDay.of(8, 28); // print instance System.out.println("MonthDay before" + " applying method: " + monthday); // apply with method of MonthDay class MonthDay updatedlocal = monthday.with(Month.OCTOBER); // print instance System.out.println("MonthDay after" + " applying method: " + updatedlocal); } } Output: MonthDay before applying method: --08-28 MonthDay after applying method: --10-28 Program 2: Java // Java program to demonstrate // MonthDay.with() method import java.time.*; import java.time.temporal.*; public class GFG { public static void main(String[] args) { // create a MonthDay object MonthDay monthday = MonthDay.of(10, 31); // print instance System.out.println("MonthDay before" + " applying method: " + monthday); // apply with method of MonthDay class MonthDay updatedlocal = monthday.with(Month.FEBRUARY); // print instance System.out.println("MonthDay after" + " applying method: " + updatedlocal); } } Output: MonthDay before applying method: --10-31 MonthDay after applying method: --02-29 References: https://docs.oracle.com/javase/10/docs/api/java/time/MonthDay.html#with(java.time.Month) Comment More infoAdvertise with us Next Article MonthDay with() Method in Java with Examples A AmanSingh2210 Follow Improve Article Tags : Java Java-Functions Java-time package Java-MonthDay Practice Tags : Java Similar Reads MonthDay withMonth() Method in Java with Examples withMonth(int month) method of the MonthDay class used to alter the month-of-year of MonthDay object using month passed as a parameter and after that method returns the copy of altered MonthDay.If the day-of-month is invalid for the specified month, the day will be adjusted to the last valid day-of- 2 min read MonthDay withDayOfMonth() Method in Java with Examples withDayOfMonth(int dayOfMonth) method of the MonthDay class used to alter the day-of-month of MonthDay object using dayOfMonth passed as a parameter and after that method returns the copy of altered MonthDay.An exception is thrown If the day-of-month value is invalid for the specified month after al 2 min read MonthDay query() method in Java with Examples query() method of an MonthDay class used to query this MonthDay using the specified query as parameter.The TemporalQuery object passed as parameter define the logic to be used to obtain the result from this MonthDay. Syntax: public <R> R query(TemporalQuery<R> query) Parameters: This met 2 min read MonthDay get() method in Java with Examples The get() method of MonthDay class in Java gets the value of the specified field from this month-day as an int. Syntax: public int get(TemporalField field) Parameter: This method accepts a parameter field which specifies the field to get and not null. Returns: The function returns the value for the 2 min read MonthDay from() method in Java with Examples The from() method of MonthDay class in Java obtains an instance of MonthDay from a temporal object. Syntax: public static MonthDay from(TemporalAccessor temporal) Parameter: This method accepts a parameter temporal which specifies the temporal object to convert which is not null. Returns: The functi 1 min read Like