Java Date Time - MonthDay with(Month month) example








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

Syntax

with has the following syntax.

public MonthDay with(Month month)

Example

The following example shows how to use with.

import java.time.Month;
import java.time.MonthDay;
//w  w  w  . ja  v  a2  s  .  c om
public class Main {
  public static void main(String[] args) {
    MonthDay m = MonthDay.now();
    MonthDay n = m.with(Month.JANUARY);
    System.out.println(n);

  }
}

The code above generates the following result.