Java Date Time - OffsetDateTime withDayOfYear(int dayOfYear) example








OffsetDateTime withDayOfYear(int dayOfYear) returns a copy of this OffsetDateTime with the day-of-year altered.

Syntax

withDayOfYear has the following syntax.

public OffsetDateTime withDayOfYear(int dayOfYear)

Example

The following example shows how to use withDayOfYear.

import java.time.OffsetDateTime;

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

The code above generates the following result.