Interface Timer

All Known Subinterfaces:
Container
All Known Implementing Classes:
SystemTimer, TestTimer

public interface Timer

This class provides access to the current time in milliseconds, as viewed by the Container. Inject an instance of this class into any component that needs to access time, instead of using System.currentTimeMillis().

Author:
Simon Thoresen Hult
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static class 
     
  • Method Summary

    Modifier and Type
    Method
    Description
    default Instant
    Convenience method for getting an java.util.Instance from currentTimeMillis().
    long
    Returns the current time in milliseconds.
    static Timer
    Create a Timer backed by the given Clock.
    default Clock
    Return a UTC Clock backed by this timer.
  • Method Details

    • currentTimeMillis

      long currentTimeMillis()

      Returns the current time in milliseconds. Note that while the unit of time of the return value is a millisecond, the granularity of the value depends on the underlying operating system and may be larger. For example, many operating systems measure time in units of tens of milliseconds.

      See the description of the class Date for a discussion of slight discrepancies that may arise between "computer time" and coordinated universal time (UTC).

      Returns:
      The difference, measured in milliseconds, between the current time and midnight, January 1, 1970 UTC.
      See Also:
    • currentTime

      default Instant currentTime()
      Convenience method for getting an java.util.Instance from currentTimeMillis().
    • toUtcClock

      default Clock toUtcClock()
      Return a UTC Clock backed by this timer.
    • fromClock

      static Timer fromClock(Clock clock)
      Create a Timer backed by the given Clock.