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 MonthDay now(Clock) method in Java with Examples The now(Clock clock) method of the MonthDay class in Java is used to get the current month-day from the specified clock. Syntax: public static MonthDay now(Clock clock) Parameters: This method accepts clock as parameter which represents the clock to use. Return value: This method returns the current 1 min read MonthDay atYear() method in Java with Examples The atYear() method of MonthDay class in Java combines this month-day with a year to create a LocalDate. Syntax: public LocalDate atYear(int year) Parameter: This method accepts a parameter year which specifies the year to use which is in range [MIN_YEAR, MAX_YEAR] Returns: The function returns the 1 min read MonthDay equals() method in Java with Examples The equals() method of MonthDay class in Java checks if this month-day is equal to another month-day. Syntax: public boolean equals(Object obj) Parameter: This method accepts a parameter obj which specifies if this month-day is equal to another month-day. Returns: The function returns true if this i 1 min read MonthDay isAfter() Method in Java with Examples isAfter() method of the MonthDay class used to check if this MonthDay is after the MonthDay passed as parameter or not. This method returns a boolean value showing the same. Syntax: public boolean isAfter(MonthDay other) Parameters: This method accepts one parameter other which is the other month-da 2 min read OffsetDateTime with() Method in Java with Examples In OffsetDateTime class, there are two types of with() method depending upon the parameters passed to it. with(TemporalAdjuster adjuster) with(TemporalAdjuster adjuster) method of the OffsetDateTime class used to adjusted this OffsetDateTime using TemporalAdjuster and after adjustment returns the co 3 min read Like