Interface Clock

All Known Subinterfaces:
Scheduler, SystemClock
All Known Implementing Classes:
ClockNanoBase, DeltaClock, Scheduler.DelegatingImpl, SimulationClock, SystemClockMillis, SystemClockUtc

public interface Clock
Provides time-based methods. Callers should prefer the methods most appropriate for their use-case and desired resolution. The performance of the methods may differ depending on the resolution they provide.
See Also:
  • Method Details

    • system

      static SystemClock system()
      The SystemClock. Provides singleton semantics around SystemClock.of().
      Returns:
      the system clock
    • currentTimeMillis

      long currentTimeMillis()
      Milliseconds since the epoch, 1970-01-01T00:00:00Z.

      The resolution is dependent on the JVM and underlying implementation.

      Returns:
      epoch millis
    • currentTimeMicros

      long currentTimeMicros()
      Microseconds since the epoch, 1970-01-01T00:00:00Z.

      The resolution is dependent on the JVM and underlying implementation. The resolution is greater than or equal to currentTimeMillis().

      Returns:
      epoch microseconds
    • currentTimeNanos

      long currentTimeNanos()
      Nanoseconds since the epoch, 1970-01-01T00:00:00Z.

      The resolution is dependent on the JVM and underlying implementation. The resolution is greater than or equal to currentTimeMicros() and currentTimeMillis().

      Returns:
      epoch nanoseconds
    • instantNanos

      Instant instantNanos()
      The instant.

      Has resolution equal to currentTimeNanos().

      If you don't need the resolution provided by currentTimeNanos(), prefer instantMillis().

      Returns:
      the instant
    • instantMillis

      Instant instantMillis()
      The instant.

      Has resolution greater than or equal to currentTimeMillis().

      Returns:
      the instant.