Class Timestamp

java.lang.Object
net.dv8tion.jda.api.utils.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 Summary

    Modifier and Type
    Method
    Description
    The TimeFormat used to display this timestamp.
    long
    The unix epoch timestamp for this markdown timestamp.
    minus(long millis)
    Creates a new timestamp instance with the provided offset into the past relative to the current timestamp.
    minus(Duration duration)
    Creates a new timestamp instance with the provided offset into the past relative to the current timestamp.
    plus(long millis)
    Creates a new timestamp instance with the provided offset into the future relative to the current timestamp.
    plus(Duration duration)
    Creates a new timestamp instance with the provided offset into the future relative to the current timestamp.
    Shortcut for Instant.ofEpochMilli(getTimestamp()).
     

    Methods inherited from class java.lang.Object

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

    • getFormat

      @Nonnull public TimeFormat getFormat()
      The TimeFormat used to display this timestamp.
      Returns:
      The TimeFormat
    • 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

      @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:
    • 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

      @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:
    • toString

      public String toString()
      Overrides:
      toString in class Object