LocalTime from() method in Java


An instance of a LocalTime object can be obtained from a Temporal object using the from() method in the LocalTime class in Java. This method requires a single parameter i.e. the Temporal object and it returns the LocalTime object that is obtained from the Temporal object.

A program that demonstrates this is given as follows:

import java.time.*;
public class Main {
   public static void main(String[] args) {
      LocalTime lt = LocalTime.from(ZonedDateTime.now());
      System.out.println("The LocalTime is: " + lt);
   }
}

The output of the above program is as follows:

The LocalTime is: 10:09:29.696

Now let us understand the above program.

The instance of the LocalTime object is obtained from the Temporal object using the from() method and then it is displayed. A code snippet that demonstrates this is as follows:

LocalTime lt = LocalTime.from(ZonedDateTime.now());
System.out.println("The LocalTime is: " + lt);

Updated on: 30-Jul-2019

41 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements