LocalTime now(clock) method in Java with Examples
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:
import java.time.*;
import java.time.temporal.*;
public class GFG {
public static void main(String[] args)
{
LocalTime time = LocalTime.now(
Clock.systemUTC());
System.out.println( "Time: "
+ time);
}
}
|
Output:
Time: 21:04:28.811
Program 2:
import java.time.*;
import java.time.temporal.*;
public class GFG {
public static void main(String[] args)
{
LocalTime time = LocalTime.now(
Clock.systemUTC());
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)
Last Updated :
12 May, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...