The from() method of a LocalTime class helps to get instance of LocalTime from TemporalAccessor object passed as parameter to method. A TemporalAccessor represents an arbitrary set of date and time information and this method helps to get a LocalTime based on the specified TemporalAccessor object.
Syntax:
public static LocalTime from(TemporalAccessor temporal)
Parameters: This method accepts a single parameter temporal which is the temporal object. It should not be null.
Return value: This method returns the local time from temporal object, not null
Exception: This method throws a DateTimeException if unable to convert to a LocalTime.
Below programs illustrate the from() method:
Program 1:
// Java program to demonstrate // LocalTime.from() method import java.time.*; public class GFG { public static void main(String[] args) { // create a ZonedDateTime object ZonedDateTime zonedDateTime = ZonedDateTime.now(); // apply form() LocalTime value = LocalTime.from(zonedDateTime); // print result System.out.println("LocalTime value : " + value); } } |
LocalTime value : 06:17:32.760
Program 2:
// Java program to demonstrate // LocalTime.from() method import java.time.*; public class GFG { public static void main(String[] args) { // create a OffsetDateTime object OffsetDateTime offset = OffsetDateTime.now(); // apply form() LocalTime value = LocalTime.from(offset); // print result System.out.println("LocalTime value : " + value); } } |
LocalTime value : 06:17:35.131
Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
Recommended Posts:
- LocalTime toNanoOfDay() method in Java with Examples
- LocalTime toSecondOfDay() method in Java with Examples
- LocalTime isBefore() method in Java with Examples
- LocalTime isAfter() method in Java with Examples
- LocalTime get() method in Java with Examples
- LocalTime getLong() method in Java with Examples
- LocalTime getMinute() method in Java with Examples
- LocalTime getSecond() method in Java with Examples
- LocalTime getNano() method in Java with Examples
- LocalTime getHour() method in Java with Examples
- LocalTime hashCode() method in Java with Examples
- LocalTime format() method in Java with Examples
- LocalTime equals() method in Java with Examples
- LocalTime compareTo() method in Java with Examples
- LocalTime adjustInto() method in Java with Examples
- LocalTime atDate() method in Java with Examples
- LocalTime atOffset() method in Java with Examples
- LocalTime ofNanoOfDay() method in Java with Examples
- LocalTime ofInstant() method in Java with Examples
- LocalTime ofSecondOfDay() method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

