Studytonight is now part of the GUVI universe. Explore GUVI →
🤩 New Cool Developer Tools for you. Explore →
FREE JavaScript Video Series Start Learning →
Signup/Sign In
Tests
MCQs to test your knowledge.
Compilers
Compilers to execute code in browser.
Index
LAST UPDATED: JUNE 15, 2020

Java LocalDate from() Method With Examples

This method is used to get localdate from a TemporalAccessor instance. TemporalAccessor is an interface, any object that inherits it can be used with the from() method. The from() method converts the temporal object into a localdate. The syntax of this method is given below.

Syntax

public static LocalDate from(TemporalAccessor temporal)

Parameters:

temporal - an object to convert into localdate.

Returns:

It returns a localdate.

Example: date from() method

In this example, we are using from() method to get localdate from a TemporalAccessor object. Notice we used of() method to create date and stored into TemporalAccessor object which further is used with from() method to get localdate.

import java.time.LocalDate;
import java.time.temporal.TemporalAccessor;
public class DateDemo {
public static void main(String[] args){ 
		
		// Take a date
	 TemporalAccessor date = LocalDate.of(2012,06,02);
		// Displaying date
		System.out.println("Date : "+date);
		// from method
		LocalDate date2 = LocalDate.from(date);
		System.out.println(date2);
	}
}


Date : 2012年06月02日
2012年06月02日

Example:

In this example, we used ZonedDateTime to get the current date and assigned to temporalaccessor object that further is used with from() method to get localdate.

import java.time.LocalDate;
import java.time.ZonedDateTime;
import java.time.temporal.TemporalAccessor;
public class DateDemo {
public static void main(String[] args){ 
		
		// Take a date
	 TemporalAccessor date = ZonedDateTime.now();
		// Displaying date
		System.out.println("Date : "+date);
		// from method
		LocalDate date2 = LocalDate.from(date);
		System.out.println(date2);
	}
}


Date : 2020年06月01日T15:28:21.841342+05:30[Asia/Kolkata]
2020年06月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.

Learn to Code
Learn and practice coding side-by-side.
NEW
C language Course
115+ coding exercises
Javascript Course
85+ coding exercises

AltStyle によって変換されたページ (->オリジナル) /