Class Clock.OffsetClock

java.lang.Object
org.threeten.bp.Clock
org.threeten.bp.Clock.OffsetClock
All Implemented Interfaces:
Serializable
Enclosing class:
Clock

static final class Clock.OffsetClock extends Clock implements Serializable
Implementation of a clock that adds an offset to an underlying clock.
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      See Also:
    • baseClock

      private final Clock baseClock
    • offset

      private final Duration offset
  • Constructor Details

  • Method Details

    • getZone

      public ZoneId getZone()
      Description copied from class: Clock
      Gets the time-zone being used to create dates and times.

      A clock will typically obtain the current instant and then convert that to a date or time using a time-zone. This method returns the time-zone used.

      Specified by:
      getZone in class Clock
      Returns:
      the time-zone being used to interpret instants, not null
    • withZone

      public Clock withZone(ZoneId zone)
      Description copied from class: Clock
      Returns a copy of this clock with a different time-zone.

      A clock will typically obtain the current instant and then convert that to a date or time using a time-zone. This method returns a clock with similar properties but using a different time-zone.

      Specified by:
      withZone in class Clock
      Parameters:
      zone - the time-zone to change to, not null
      Returns:
      a clock based on this clock with the specified time-zone, not null
    • millis

      public long millis()
      Description copied from class: Clock
      Gets the current millisecond instant of the clock.

      This returns the millisecond-based instant, measured from 1970-01-01T00:00 UTC. This is equivalent to the definition of System.currentTimeMillis().

      Most applications should avoid this method and use Instant to represent an instant on the time-line rather than a raw millisecond value. This method is provided to allow the use of the clock in high performance use cases where the creation of an object would be unacceptable. The default implementation currently calls Clock.instant().

      Overrides:
      millis in class Clock
      Returns:
      the current millisecond instant from this clock, measured from the Java epoch of 1970-01-01T00:00 UTC, not null
    • instant

      public Instant instant()
      Description copied from class: Clock
      Gets the current instant of the clock.

      This returns an instant representing the current instant as defined by the clock.

      Specified by:
      instant in class Clock
      Returns:
      the current instant from this clock, not null
    • equals

      public boolean equals(Object obj)
      Description copied from class: Clock
      Checks if this clock is equal to another clock.

      Clocks must compare equal based on their state and behavior.

      Overrides:
      equals in class Clock
      Parameters:
      obj - the object to check, null returns false
      Returns:
      true if this is equal to the other clock
    • hashCode

      public int hashCode()
      Description copied from class: Clock
      A hash code for this clock.
      Overrides:
      hashCode in class Clock
      Returns:
      a suitable hash code
    • toString

      public String toString()
      Overrides:
      toString in class Object