Interface Timestamp


public interface Timestamp
A point in time independent of any time zone or calendar, represented as milliseconds in UTC Unix Epoch time.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final Timestamp
    The maximum allowed Timestamp of UTC time since Unix epoch.
    static final Timestamp
    The Timestamp from the number of microseconds of UTC time since Unix epoch 1970-01-01T00:00:00Z set to none.
  • Method Summary

    Modifier and Type
    Method
    Description
    static Timestamp
    Creates a Timestamp from the given Instant.
    static Timestamp
    fromMicros(long microseconds)
    Creates a Timestamp from the number of microseconds of UTC time since Unix epoch 1970-01-01T00:00:00Z.
    static Timestamp
    fromMillis(long milliseconds)
    Creates a Timestamp from the number of milliseconds of UTC time since Unix epoch 1970-01-01T00:00:00Z.
    static Timestamp
    fromSeconds(long seconds)
    Creates a Timestamp from the number of seconds of UTC time since Unix epoch 1970-01-01T00:00:00Z.
    default Instant
    Converts this Timestamp to an Instant.
    default long
    Returns the number of microseconds of UTC time since Unix epoch 1970-01-01T00:00:00Z.
    default long
    Returns the number of milliseconds of UTC time since Unix epoch 1970-01-01T00:00:00Z.
    default long
    Returns the number of seconds of UTC time since Unix epoch 1970-01-01T00:00:00Z.
  • Field Details

    • NONE

      static final Timestamp NONE
      The Timestamp from the number of microseconds of UTC time since Unix epoch 1970-01-01T00:00:00Z set to none.
    • MAX

      static final Timestamp MAX
      The maximum allowed Timestamp of UTC time since Unix epoch. An equivalent to 9999-12-31T23:59:59Z.
  • Method Details

    • fromSeconds

      static Timestamp fromSeconds(long seconds)
      Creates a Timestamp from the number of seconds of UTC time since Unix epoch 1970-01-01T00:00:00Z.
      Parameters:
      seconds - the number of seconds of UTC time since Unix epoch 1970-01-01T00:00:00Z
      Returns:
      a Timestamp from the number of seconds of UTC time since Unix epoch
      Throws:
      IllegalArgumentException - when the seconds argument is negative
    • fromMillis

      static Timestamp fromMillis(long milliseconds)
      Creates a Timestamp from the number of milliseconds of UTC time since Unix epoch 1970-01-01T00:00:00Z.
      Parameters:
      milliseconds - the number of milliseconds of UTC time since Unix epoch 1970-01-01T00:00:00Z
      Returns:
      a Timestamp from the number of milliseconds of UTC time since Unix epoch
      Throws:
      IllegalArgumentException - when the milliseconds argument is negative
    • fromMicros

      static Timestamp fromMicros(long microseconds)
      Creates a Timestamp from the number of microseconds of UTC time since Unix epoch 1970-01-01T00:00:00Z.
      Parameters:
      microseconds - the number of microseconds of UTC time since Unix epoch 1970-01-01T00:00:00Z
      Returns:
      a Timestamp from the number of microseconds of UTC time since Unix epoch
      Throws:
      IllegalArgumentException - when the microseconds argument is negative
    • fromInstant

      static Timestamp fromInstant(Instant instant)
      Creates a Timestamp from the given Instant.

      Instant is based on nanosecond precision, while Timestamp is based on microseconds. Since Timestamp has less precision, any additional nanoseconds in the Instant will be truncated. This does not result in a loss of precision relevant to Timestamp, as it cannot store nanoseconds.

      Parameters:
      instant - an Instant to create a Timestamp from
      Returns:
      a Timestamp that represents the same point in time as the given Instant, truncated to microsecond precision
    • toMicros

      default long toMicros()
      Returns the number of microseconds of UTC time since Unix epoch 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59Z inclusive.
      Returns:
      the number of microseconds of UTC time since Unix epoch
    • toMillis

      default long toMillis()
      Returns the number of milliseconds of UTC time since Unix epoch 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59Z inclusive.
      Returns:
      the number of milliseconds of UTC time since Unix epoch
    • toSeconds

      default long toSeconds()
      Returns the number of seconds of UTC time since Unix epoch 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59Z inclusive.
      Returns:
      the number of seconds of UTC time since Unix epoch
    • toInstant

      default Instant toInstant()
      Converts this Timestamp to an Instant.

      Timestamp is based on microseconds, while Instant offers nanosecond precision. Since Timestamp is less precise, the conversion to Instant will not result in any loss of precision. The additional nanoseconds are simply set to zero.

      Returns:
      an instance of Instant that represents the same point in time as this Timestamp