Class Timestamp


  • public class Timestamp
    extends java.lang.Object
    Utility class representing Discord Markdown timestamps.
    This class implements toString() such that it can be directly included in message content.

    These timestamps are rendered by the individual receiving Discord client in a local timezone and language format. Each timestamp can be displayed with different TimeFormats.

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      TimeFormat getFormat()
      The TimeFormat used to display this timestamp.
      long getTimestamp()
      The unix epoch timestamp for this markdown timestamp.
      Timestamp minus​(long millis)
      Creates a new timestamp instance with the provided offset into the past relative to the current timestamp.
      Timestamp minus​(java.time.Duration duration)
      Creates a new timestamp instance with the provided offset into the past relative to the current timestamp.
      Timestamp plus​(long millis)
      Creates a new timestamp instance with the provided offset into the future relative to the current timestamp.
      Timestamp plus​(java.time.Duration duration)
      Creates a new timestamp instance with the provided offset into the future relative to the current timestamp.
      java.time.Instant toInstant()
      Shortcut for Instant.ofEpochMilli(getTimestamp()).
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Method Detail

      • getTimestamp

        public long getTimestamp()
        The unix epoch timestamp for this markdown timestamp.
        This is similar to System.currentTimeMillis() and provided in millisecond precision for easier compatibility. Discord uses seconds precision instead.
        Returns:
        The millisecond unix epoch timestamp
      • toInstant

        @Nonnull
        public java.time.Instant toInstant()
        Shortcut for Instant.ofEpochMilli(getTimestamp()).
        Returns:
        The Instant of this timestamp
      • plus

        @Nonnull
        public Timestamp plus​(long millis)
        Creates a new timestamp instance with the provided offset into the future relative to the current timestamp.
        Parameters:
        millis - The millisecond offset for the new timestamp
        Returns:
        Copy of this timestamp with the relative offset
        See Also:
        plus(Duration)
      • plus

        @Nonnull
        public Timestamp plus​(@Nonnull
                              java.time.Duration duration)
        Creates a new timestamp instance with the provided offset into the future relative to the current timestamp.
        Parameters:
        duration - The offset for the new timestamp
        Returns:
        Copy of this timestamp with the relative offset
        Throws:
        java.lang.IllegalArgumentException - If the provided duration is null
        See Also:
        plus(long)
      • minus

        @Nonnull
        public Timestamp minus​(long millis)
        Creates a new timestamp instance with the provided offset into the past relative to the current timestamp.
        Parameters:
        millis - The millisecond offset for the new timestamp
        Returns:
        Copy of this timestamp with the relative offset
        See Also:
        minus(Duration)
      • minus

        @Nonnull
        public Timestamp minus​(@Nonnull
                               java.time.Duration duration)
        Creates a new timestamp instance with the provided offset into the past relative to the current timestamp.
        Parameters:
        duration - The offset for the new timestamp
        Returns:
        Copy of this timestamp with the relative offset
        Throws:
        java.lang.IllegalArgumentException - If the provided duration is null
        See Also:
        minus(long)
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object