Java Date Time - LocalDateTime withDayOfYear(int dayOfYear) example








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

Syntax

withDayOfYear has the following syntax.

public LocalDateTime withDayOfYear(int dayOfYear)

Example

The following example shows how to use withDayOfYear.

import java.time.LocalDateTime;
/*from ww w .j  a va  2s  .c  o m*/
public class Main {
  public static void main(String[] args) {
    LocalDateTime a = LocalDateTime.of(2014, 6, 30, 12, 01);
    
    LocalDateTime t = a.withDayOfYear(2012);
    
    System.out.println(t);
  }
}