java.time.Clock.tickSeconds() Method Example



Description

The java.time.Clock.tickSeconds() method obtains a clock that returns the current instant ticking in whole seconds using best available system clock.

Declaration

Following is the declaration for java.time.Clock.tickSeconds() method.

public static Clock tickSeconds(ZoneId zone)

Parameters

zone − the time-zone to use to convert the instant to date-time, not null.

Return Value

a clock that ticks in whole seconds using the specified zone, not null.

Example

The following example shows the usage of java.time.Clock.tickSeconds() method.

package com.tutorialspoint;

import java.time.Clock;
import java.time.ZoneId;

public class ClockDemo {
   public static void main(String[] args) {
   
      Clock clock = Clock.systemDefaultZone();
      Clock clock1 = Clock.tickSeconds(ZoneId.systemDefault());
      System.out.println("Clock : " + clock.instant());
      System.out.println("Clock1 : " + clock1.instant());
   }
}

Let us compile and run the above program, this will produce the following result −

Clock : 2017-03-07T06:58:34.526Z
Clock1 : 2017-03-07T06:58:34Z
Advertisements