Package net.dv8tion.jda.api.utils
Enum TimeFormat
- All Implemented Interfaces:
Serializable,Comparable<TimeFormat>
Utility enum used to provide different markdown styles for timestamps.
These can be used to represent a unix epoch timestamp in different formats.
These can be used to represent a unix epoch timestamp in different formats.
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.
Example
channel.sendMessage("Current Time: " + TimeFormat.RELATIVE.now()).queue();
channel.sendMessage("Uptime: " + TimeFormat.RELATIVE.format(getStartTime())).queue();
-
Enum Constant Summary
Enum ConstantsEnum ConstantDescriptionFormats date as16 June 2021Formats date as16/06/2021or06/16/2021Formats date and time asWednesday, 16 June 2021 18:49orWednesday, June 16, 2021 6:49 PMFormats date and time as16 June 2021 18:49orJune 16, 2021 6:49 PMFormats date and time as relative18 minutes agoor2 days agoFormats time as18:49:26or6:49:26 PMFormats time as18:49or6:49 PM -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final TimeFormatThe default time format used when no style is provided.static final PatternPatternused forparse(String). -
Method Summary
Modifier and TypeMethodDescriptionafter(long millis) Shortcut forstyle.now().plus(millis).Shortcut forstyle.now().plus(duration).atTimestamp(long timestamp) Converts the provided unix epoch timestamp into aTimestampwith this style.before(long millis) Shortcut forstyle.now().minus(millis).Shortcut forstyle.now().minus(duration).format(long timestamp) Formats the provided unix epoch timestamp into a timestamp markdown.format(TemporalAccessor temporal) Formats the providedTemporalAccessorinstance into a timestamp markdown.static TimeFormatReturns the time format for the provided style flag.getStyle()The display style flag used for the markdown representation.now()Shortcut forstyle.atTimestamp(System.currentTimeMillis()).static TimestampParses the provided markdown into aTimestampinstance.static TimeFormatReturns the enum constant of this type with the specified name.static TimeFormat[]values()Returns an array containing the constants of this enum type, in the order they are declared.
-
Enum Constant Details
-
TIME_SHORT
Formats time as18:49or6:49 PM -
TIME_LONG
Formats time as18:49:26or6:49:26 PM -
DATE_SHORT
Formats date as16/06/2021or06/16/2021 -
DATE_LONG
Formats date as16 June 2021 -
DATE_TIME_SHORT
Formats date and time as16 June 2021 18:49orJune 16, 2021 6:49 PM -
DATE_TIME_LONG
Formats date and time asWednesday, 16 June 2021 18:49orWednesday, June 16, 2021 6:49 PM -
RELATIVE
Formats date and time as relative18 minutes agoor2 days ago
-
-
Field Details
-
DEFAULT
The default time format used when no style is provided. -
MARKDOWN
Patternused forparse(String).Groups
Index Name Description 0 N/A The entire timestamp markdown 1 time The timestamp value as a unix epoch in second precision 2 style The style used for displaying the timestamp (single letter flag) - See Also:
-
-
Method Details
-
values
Returns an array containing the constants of this enum type, in the order they are declared.- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
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
The display style flag used for the markdown representation.
This is encoded into the markdown to provide the client with rendering context.- Returns:
- The style flag
-
fromStyle
Returns the time format for the provided style flag.- Parameters:
style- The style flag- Returns:
- The representative TimeFormat or
DEFAULTif none could be identified - Throws:
IllegalArgumentException- If the provided style string is not exactly one character long
-
parse
Parses the provided markdown into aTimestampinstance.
This is the reverse operation for theTimestamp.toString()representation.- Parameters:
markdown- The markdown for the timestamp value- Returns:
Timestampinstance for the provided markdown- Throws:
IllegalArgumentException- If the provided markdown is null or does not match theMARKDOWNpattern
-
format
Formats the providedTemporalAccessorinstance into a timestamp markdown.- Parameters:
temporal- TheTemporalAccessor- Returns:
- The markdown string with this encoded style
- Throws:
IllegalArgumentException- If the provided temporal instance is nullDateTimeException- If the temporal accessor cannot be converted to an instant- See Also:
-
format
Formats the provided unix epoch timestamp into a timestamp markdown.
Compatible with millisecond precision timestamps such as the ones provided bySystem.currentTimeMillis().- Parameters:
timestamp- The millisecond epoch- Returns:
- The markdown string with this encoded style
-
atInstant
- Parameters:
instant- TheInstantfor the timestamp- Returns:
- The
Timestampinstance - Throws:
IllegalArgumentException- If null is provided- See Also:
-
atTimestamp
Converts the provided unix epoch timestamp into aTimestampwith this style.
Compatible with millisecond precision timestamps such as the ones provided bySystem.currentTimeMillis().- Parameters:
timestamp- The millisecond epoch- Returns:
- The
Timestampinstance - See Also:
-
now
Shortcut forstyle.atTimestamp(System.currentTimeMillis()).- Returns:
Timestampinstance for the current time- See Also:
-
after
Shortcut forstyle.now().plus(duration).- Parameters:
duration- TheDurationoffset into the future- Returns:
Timestampinstance for the offset relative to the current time- Throws:
IllegalArgumentException- If null is provided- See Also:
-
after
Shortcut forstyle.now().plus(millis).- Parameters:
millis- The millisecond offset into the future- Returns:
Timestampinstance for the offset relative to the current time- See Also:
-
before
Shortcut forstyle.now().minus(duration).- Parameters:
duration- TheDurationoffset into the past- Returns:
Timestampinstance for the offset relative to the current time- Throws:
IllegalArgumentException- If null is provided- See Also:
-
before
Shortcut forstyle.now().minus(millis).- Parameters:
millis- The millisecond offset into the past- Returns:
Timestampinstance for the offset relative to the current time- See Also:
-