java.time.MonthDay.with() Method Example



Description

The java.time.MonthDay.with(Month month) method returns a copy of this MonthDay with the month-of-year altered.

Declaration

Following is the declaration for java.time.MonthDay.with(Month month) method.

public MonthDay with(Month month)

Parameters

month − the month-of-year to set in the returned month-day, not null.

Return Value

a MonthDay based on this month-day with the requested month, not null.

Example

The following example shows the usage of java.time.MonthDay.with(Month month) method.

package com.tutorialspoint;

import java.time.Month;
import java.time.MonthDay;

public class MonthDayDemo {
   public static void main(String[] args) {
      
      MonthDay time = MonthDay.parse("--10-15");
      MonthDay result = time.with(Month.APRIL);
      System.out.println(result);  
   }
}

Let us compile and run the above program, this will produce the following result −

--04-15
Advertisements