Java Date Time - OffsetDateTime withDayOfMonth(int dayOfMonth) example








OffsetDateTime withDayOfMonth(int dayOfMonth) returns a copy of this OffsetDateTime with the day-of-month altered.

Syntax

withDayOfMonth has the following syntax.

public OffsetDateTime withDayOfMonth(int dayOfMonth)

Example

The following example shows how to use withDayOfMonth.

import java.time.OffsetDateTime;

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

The code above generates the following result.