Programming for fun and profit

Programming tutorials, problems, solutions. Always with code.

Java Time Clock tickSeconds(ZoneId)


The method Clock.tickSeconds(ZoneId zone) returns a clock that will tick in seconds using the best available clock (usually system clock).

Method signature

The signature of the java.time.Clock.tickSeconds(ZoneId) method is as follows:

public static Clock tickSeconds(ZoneId zone)

The method is available since Java 8.


  • ZoneId zone: the time-zone that will be used to convert the instant to date-time, not null.

Return value

Returns a clock that ticks in seconds using the given time-zone, never null.


  • NullPointerException: if the zone is null.

Example usage

In the following code we use java.time.Clock.tickSeconds(ZoneId):


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

public class ClockExample {

    public static void main(String[] args) throws InterruptedException {
        // Clocks:
        Clock sysClock = Clock.systemDefaultZone();
        Clock laClock = Clock.tickSeconds(
        Clock kaClock = Clock.tickSeconds(

        // millis from the start of the epoch:
        System.out.println("Sys clock millis: "
                + sysClock.millis());
        System.out.println("LA clock millis : "
                + laClock.millis());
        System.out.println("KA clock millis : "
                + kaClock.millis());

        // date time with zone:
        System.out.println("System clock time  : "
        System.out.println("LA time tickSeconds: "
        System.out.println("KA time tickSeconds: "

The above code produces the following output:

Sys clock millis: 1464950461956
LA clock millis : 1464950461000
KA clock millis : 1464950461000
System clock time  : 2016-06-03T12:41:01.957+02:00[Europe/Warsaw]
LA time tickSeconds: 2016-06-03T03:41:02-07:00[America/Los_Angeles]
KA time tickSeconds: 2016-06-03T12:41:02+02:00[Europe/Kaliningrad]
Share with the World!