Class DiscordTimestampUtil
java.lang.Object
net.joseplay.allianceutils.api.discord.utils.DiscordTimestampUtil
Utility class for generating Discord-compatible timestamps.
Supports both:
- ISO-8601 format (used in embeds)
- Discord formatted timestamps (invalid input: '<'t:epoch:style>)
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringfromInstant(Instant instant) Converts an Instant into ISO-8601 format.static Stringnow()Returns the current timestamp in ISO-8601 format.static StringReturns a relative timestamp for the current time.static Stringtext(Instant instant, DiscordTimeStyle style) Formats a timestamp using Discord's special syntax.static StringwithOffset(long amount, ChronoUnit unit) Generates an ISO-8601 timestamp with time offset.
-
Constructor Details
-
DiscordTimestampUtil
public DiscordTimestampUtil()
-
-
Method Details
-
now
Returns the current timestamp in ISO-8601 format. Used for Discord embed timestamps.- Returns:
- Current timestamp as ISO-8601 string
-
fromInstant
Converts an Instant into ISO-8601 format. Useful for embed timestamp fields.- Parameters:
instant- Target instant- Returns:
- ISO-8601 formatted timestamp
-
withOffset
Generates an ISO-8601 timestamp with time offset. Example: +5 minutes, -2 hours, etc.- Parameters:
amount- Amount to offsetunit- Time unit (e.g., MINUTES, HOURS)- Returns:
- Offset timestamp in ISO-8601 format
-
text
Formats a timestamp using Discord's special syntax. Format: invalid input: '<'t:epoch:style> Example: invalid input: '<'t:1699999999:R> → "2 minutes ago"- Parameters:
instant- Target instantstyle- Discord display style- Returns:
- Formatted Discord timestamp string
-
relativeNow
Returns a relative timestamp for the current time. Example output: "a few seconds ago"- Returns:
- Discord relative timestamp string
-