Enum Class TimestampFormat

java.lang.Object
java.lang.Enum<TimestampFormat>
discord4j.common.util.TimestampFormat
All Implemented Interfaces:
Serializable, Comparable<TimestampFormat>, Constable

public enum TimestampFormat extends Enum<TimestampFormat>
A utility class for formatting a Java Instant as a timestamp in Discord messages.
See Also:
  • Enum Constant Details

    • DEFAULT

      public static final TimestampFormat DEFAULT
      Example: 20 April 2021 16:20
    • SHORT_TIME

      public static final TimestampFormat SHORT_TIME
      Example: 16:20
    • LONG_TIME

      public static final TimestampFormat LONG_TIME
      Example: 16:20:30
    • SHORT_DATE

      public static final TimestampFormat SHORT_DATE
      Example: 20/04/2021
    • LONG_DATE

      public static final TimestampFormat LONG_DATE
      Example: 20 April 2021
    • SHORT_DATE_TIME

      public static final TimestampFormat SHORT_DATE_TIME
      Example: 20 April 2021 16:20
    • LONG_DATE_TIME

      public static final TimestampFormat LONG_DATE_TIME
      Example: Tuesday, 20 April 2021 16:20
    • RELATIVE_TIME

      public static final TimestampFormat RELATIVE_TIME
      Example: 2 months ago
  • Method Details

    • values

      public static TimestampFormat[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static TimestampFormat valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null
    • getStyle

      public String getStyle()
      Get the style (1 character) for this timestamp format. The default format returns an empty string.
      Returns:
      The style character as a String
    • format

      public String format(Instant instant)
      Gets the markdown representation of the provided Instant for this style. In a message, Discord will display the timestamp in the user's local timezone.
      Parameters:
      instant - the Instant to construct a timestamp with.
      Returns:
      The markdown representation of the Instant as a String.