Package net.dv8tion.jda.api.utils
Class Timestamp
- java.lang.Object
-
- net.dv8tion.jda.api.utils.Timestamp
-
public class Timestamp extends java.lang.Object
Utility 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 TimeFormat
getFormat()
TheTimeFormat
used to display this timestamp.long
getTimestamp()
The unix epoch timestamp for this markdown timestamp.Timestamp
minus(long millis)
Creates a new timestamp instance with the provided offset into the past relative to the current timestamp.Timestamp
minus(java.time.Duration duration)
Creates a new timestamp instance with the provided offset into the past relative to the current timestamp.Timestamp
plus(long millis)
Creates a new timestamp instance with the provided offset into the future relative to the current timestamp.Timestamp
plus(java.time.Duration duration)
Creates a new timestamp instance with the provided offset into the future relative to the current timestamp.java.time.Instant
toInstant()
Shortcut forInstant.ofEpochMilli(getTimestamp())
.java.lang.String
toString()
-
-
-
Method Detail
-
getFormat
@Nonnull public TimeFormat getFormat()
TheTimeFormat
used 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
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(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:
toString
in classjava.lang.Object
-
-