Open In App

LocalTime now(clock) method in Java with Examples

Last Updated : 12 May, 2020
Summarize
Comments
Improve
Suggest changes
Share
Like Article
Like
Report
The now(Clock clock) method of the LocalTime class in Java is used to get the current time from the specified clock. Syntax:
public static LocalTime now(
    Clock clock)
Parameters: This method accepts clock as parameter which represents the clock to use. Return value: This method returns the current time. Below programs illustrate the now(Clock clock) method of LocalTime in Java: Program 1: Java
// Java program to demonstrate
// LocalTime.now(Clock clock) method

import java.time.*;
import java.time.temporal.*;

public class GFG {
    public static void main(String[] args)
    {

        // apply now(Clock clock) method
        // of LocalTime class
        LocalTime time = LocalTime.now(
            Clock.systemUTC());

        // print time
        System.out.println("Time: "
                           + time);
    }
}
Output:
Time: 21:04:28.811
Program 2: Java
// Java program to demonstrate
// LocalTime.now(Clock clock) method

import java.time.*;
import java.time.temporal.*;

public class GFG {
    public static void main(String[] args)
    {

        // apply now(Clock clock) method
        // of LocalTime class
        LocalTime time = LocalTime.now(
            Clock.systemUTC());

        // print time
        System.out.println("Time: "
                           + time);
    }
}
Output:
Time: 21:05:21.192
Above two examples are taken to show the variance in result for same program according to time progression. References: https://docs.oracle.com/javase/10/docs/api/java/time/LocalTime.html#now(java.time.Clock)

Practice Tags :

Similar Reads