- The now() method of OffsetTime class in Java obtains the current time from the system clock in the default time-zone.
Syntax :
public static OffsetTime now()
Parameter: This method does not accepts any parameter.
Return Value: It returns the current time using the system clock and default time-zone and not null.
Below programs illustrate the now() method:
Program 1 :
// Java program to demonstrate the now() methodimportjava.time.OffsetTime;publicclassGFG {publicstaticvoidmain(String[] args){// Parses the timeOffsetTime time = OffsetTime.now();// Prints the current timeSystem.out.println("Current time: "+ time);}}Output:Current time: 02:58:01.700Z
- The now(clock) method of OffsetTime class in Java obtains the current time from the specified clock in the parameter.
Syntax :
public static OffsetTime now(Clock clock)
Parameter: This method accepts a single parameter clock which specifies the clock to use and not null.
Return Value: It returns the current time and not null.
Below programs illustrate the now(clock) method:
Program 1 :
// Java program to demonstrate the now(clock) methodimportjava.time.OffsetTime;importjava.time.Clock;publicclassGFG {publicstaticvoidmain(String[] args){// Parses the timeOffsetTime time = OffsetTime.now();// Prints the current timeSystem.out.println("Current time: "+ Clock.systemUTC());}}Output:Current time: SystemClock[Z]
- The now(zone) method of OffsetTime class in Java obtains the current time from the system clock in the specified time-zone in the parameter.
Syntax :
public static OffsetTime now(ZoneId zone)
Parameter: This method accepts a single parameter zone which specifies the zone ID to use, not null.
Return Value: It returns the current time and not null.
Below programs illustrate the now(clock) method:
Program 1 :
// Java program to demonstrate the now(clock) methodimportjava.time.OffsetTime;importjava.time.ZoneId;publicclassGFG {publicstaticvoidmain(String[] args){// Parses the timeOffsetTime time = OffsetTime.now();// Prints the current timeSystem.out.println("Current time: "+ ZoneId.systemDefault());}}Output:Current time: Etc/UTC
Reference: https://docs.oracle.com/javase/8/docs/api/java/time/OffsetTime.html#now-long-

… [Trackback]
[…] Information to that Topic: geeksforgeeks.org/offsettime-now-method-in-java-with-examples/ […]
… [Trackback]
[…] Find More on that Topic: geeksforgeeks.org/offsettime-now-method-in-java-with-examples/ […]
… [Trackback]
[…] Here you will find 64202 more Information to that Topic: geeksforgeeks.org/offsettime-now-method-in-java-with-examples/ […]
… [Trackback]
[…] Info to that Topic: geeksforgeeks.org/offsettime-now-method-in-java-with-examples/ […]
… [Trackback]
[…] Find More on that Topic: geeksforgeeks.org/offsettime-now-method-in-java-with-examples/ […]
… [Trackback]
[…] Find More here on that Topic: geeksforgeeks.org/offsettime-now-method-in-java-with-examples/ […]