java.time.LocalDate.ofYearDay() Method Example



Description

The java.time.LocalDate.ofYearDay(int year, int dayOfYear) method obtains an instance of LocalDate from a year and day-of-year.

Declaration

Following is the declaration for java.time.LocalDate.ofYearDay(int year, int dayOfYear) method.

public static LocalDate ofYearDay(int year, int dayOfYear)

Parameters

  • year − the year to represent, from MIN_YEAR to MAX_YEAR.

  • dayOfYear − the day-of-year to represent, from 1 to 366.

Return Value

the local date, not null.

Exceptions

DateTimeException − if the value of any field is out of range, or if the day-of-year is invalid for the year.

Example

The following example shows the usage of java.time.LocalDate.ofYearDay(int year, int dayOfYear) method.

package com.tutorialspoint;

import java.time.LocalDate;

public class LocalDateDemo {
   public static void main(String[] args) {
	  
      LocalDate date = LocalDate.ofYearDay(2017,34);
      System.out.println(date);  
   }
}

Let us compile and run the above program, this will produce the following result −

2017-02-03
Advertisements