Convert ZonedDateTime to LocalTime Example

ZonedDateTime class provide toLocalTime() API to convert from ZonedDateTime to LocalTime in Java.

Convert ZonedDateTime to LocalTime Example

import java.time.LocalTime;
import java.time.ZonedDateTime;

/**
 * Program to demonstrate ZonedDateTime Class APIs.
 * @author javaguides.net
 *
 */
public class ZonedDateTimeExample {
 
    public static void main(String[] args) {
         getInstances();
    }

    private static void getInstances() {
       // Current date time with zone
        ZonedDateTime dateTime = ZonedDateTime.now();
        System.out.println(dateTime);

        // Get LocalTime
        LocalTime localTime = dateTime.toLocalTime();
        System.out.println(localTime);
    }
}
Output:
2019-06-16T13:38:59.061Z[Etc/UTC]
13:38:59.061

Reference


Comments