Package discord4j.common.util
Enum TimestampFormat
- java.lang.Object
-
- java.lang.Enum<TimestampFormat>
-
- discord4j.common.util.TimestampFormat
-
- All Implemented Interfaces:
Serializable
,Comparable<TimestampFormat>
public enum TimestampFormat extends Enum<TimestampFormat>
A utility class for formatting a JavaInstant
as a timestamp in Discord messages.- See Also:
- Timestamp message formatting
-
-
Enum Constant Summary
Enum Constants Enum Constant Description DEFAULT
Example:20 April 2021 16:20
LONG_DATE
Example:20 April 2021
LONG_DATE_TIME
Example:Tuesday, 20 April 2021 16:20
LONG_TIME
Example:16:20:30
RELATIVE_TIME
Example:2 months ago
SHORT_DATE
Example:20/04/2021
SHORT_DATE_TIME
Example:20 April 2021 16:20
SHORT_TIME
Example:16:20
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description String
format(Instant instant)
Gets the markdown representation of the providedInstant
for this style.String
getStyle()
Get the style (1 character) for this timestamp format.static TimestampFormat
valueOf(String name)
Returns the enum constant of this type with the specified name.static TimestampFormat[]
values()
Returns an array containing the constants of this enum type, in the order they are declared.
-
-
-
Enum Constant Detail
-
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 Detail
-
values
public static TimestampFormat[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:for (TimestampFormat c : TimestampFormat.values()) System.out.println(c);
- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
public static TimestampFormat valueOf(String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (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 type has no constant with the specified nameNullPointerException
- 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 providedInstant
for this style. In a message, Discord will display the timestamp in the user's local timezone.- Parameters:
instant
- theInstant
to construct a timestamp with.- Returns:
- The markdown representation of the
Instant
as a String.
-
-