Java Date Time - MonthDay with(Month month) example

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


with has the following syntax.

public MonthDay with(Month month)


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 n = m.with(Month.JANUARY);


The code above generates the following result.