Package net.dv8tion.jda.api.utils
Class Timestamp
- java.lang.Object
-
- net.dv8tion.jda.api.utils.Timestamp
-
public class Timestamp extends java.lang.ObjectUtility class representing Discord Markdown timestamps.
This class implementstoString()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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description TimeFormatgetFormat()TheTimeFormatused to display this timestamp.longgetTimestamp()The unix epoch timestamp for this markdown timestamp.Timestampminus(long millis)Creates a new timestamp instance with the provided offset into the past relative to the current timestamp.Timestampminus(java.time.Duration duration)Creates a new timestamp instance with the provided offset into the past relative to the current timestamp.Timestampplus(long millis)Creates a new timestamp instance with the provided offset into the future relative to the current timestamp.Timestampplus(java.time.Duration duration)Creates a new timestamp instance with the provided offset into the future relative to the current timestamp.java.time.InstanttoInstant()Shortcut forInstant.ofEpochMilli(getTimestamp()).java.lang.StringtoString()
-
-
-
Method Detail
-
getFormat
@Nonnull public TimeFormat getFormat()
TheTimeFormatused to display this timestamp.- Returns:
- The
TimeFormat
-
getTimestamp
public long getTimestamp()
The unix epoch timestamp for this markdown timestamp.
This is similar toSystem.currentTimeMillis()and provided in millisecond precision for easier compatibility. Discord uses seconds precision instead.- Returns:
- The millisecond unix epoch timestamp
-
toInstant
@Nonnull public java.time.Instant toInstant()
Shortcut forInstant.ofEpochMilli(getTimestamp()).- Returns:
- The
Instantof 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 java.time.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:
java.lang.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 java.time.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:
java.lang.IllegalArgumentException- If the provided duration is null- See Also:
minus(long)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-