Java Date Time - OffsetDateTime withMonth(int month) example








OffsetDateTime withMonth(int month) returns a copy of this OffsetDateTime with the month-of-year altered.

Syntax

withMonth has the following syntax.

public OffsetDateTime withMonth(int month)

Example

The following example shows how to use withMonth.

import java.time.OffsetDateTime;

public class Main {
  public static void main(String[] args) {
    OffsetDateTime o = OffsetDateTime.now();
    OffsetDateTime d = o.withMonth(3);
    System.out.println(d);
  }
}

The code above generates the following result.