Signup/Sign In
LAST UPDATED: NOVEMBER 24, 2020

Java LocalDate ofEpochDay() Method

Java LocalDate ofEpochDay() method is used to get a localdate from the epoch-day count. The epoch-day is a simple incrementing count of days from 1970-01-01.

We can use it to get an instance of LocalDate from the specified epoch day count. For example, if we pass 31 epoch day then we get 1970-02-01 which denotes a date after a month.

Syntax

public static LocalDate ofEpochDay(long epochDay)

Parameters:

It takes a single parameter of long type.

Returns:

It returns a local date.

Time for an Example:

Let's take an example to get a date 10 days ahead by using ofEpochDay() method. Here, we passed 10 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.ofEpochDay(10);
		System.out.println(localDate);		
	}
}


1970-01-11

Time for another Example:

Let''s take another example to understand the ofEpochDay() method. Here, we are getting a date ahead of 1 year by adding 365 epoch days.

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


1971-01-01

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.