Signup/Sign In

Java LocalDate ofYearDay() Method

Java LocalDate ofYearDay() method is used to get a localdate from the specified year and number of days. For example, if we want to know the date of 55th day of year 2015 then the result would be 2015-02-24.

It a LocalDate with the specified year and day-of-year. The day-of-year must be valid for the year, otherwise an exception will be thrown.

Syntax

public static LocalDate ofYearDay(int year, int dayOfYear)

Parameters:

It takes two parameters first is year and second is day-of-year.

Returns:

It returns a local date.

Time for an Example:

Let's take an example to get a date of 10th day of 2015 by using the ofYearDay() method. Here, we passed 2015 as year and 10 as days to the method and get a new local date.

import java.time.LocalDate;
public class DateDemo {
	
	public static void main(String[] args){  
		
		LocalDate localDate = LocalDate.ofYearDay(2015, 10);
		System.out.println(localDate);		
	}
}


1970-01-11

Time for another Example:

Let''s take another example to understand the ofYearDay() method. Here, we are getting a date of 100th day of year 2015 by passing 2015 as year and 100 as day-of-year.

import java.time.LocalDate;
public class DateDemo {
	
	public static void main(String[] args){  
		
		LocalDate localDate = LocalDate.ofYearDay(2015, 100);
		System.out.println(localDate);		
	}
}


2015-04-10

Live Example:

Try with a live example, execute the code instantly with our powerful Online Java Compiler.



About the author:
I am a 3rd-year Computer Science Engineering student at Vellore Institute of Technology. I like to play around with new technologies and love to code.