Class Timestamp


  • public class Timestamp
    extends 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 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 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
                              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:
        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
                               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:
        IllegalArgumentException - If the provided duration is null
        See Also:
        minus(long)