Class DiscordTimestampUtil

java.lang.Object
net.joseplay.allianceutils.api.discord.utils.DiscordTimestampUtil

public final class DiscordTimestampUtil extends Object
Utility class for generating Discord-compatible timestamps. Supports both: - ISO-8601 format (used in embeds) - Discord formatted timestamps (invalid input: '<'t:epoch:style>)
  • Constructor Details

    • DiscordTimestampUtil

      public DiscordTimestampUtil()
  • Method Details

    • now

      public static String now()
      Returns the current timestamp in ISO-8601 format. Used for Discord embed timestamps.
      Returns:
      Current timestamp as ISO-8601 string
    • fromInstant

      public static String fromInstant(Instant instant)
      Converts an Instant into ISO-8601 format. Useful for embed timestamp fields.
      Parameters:
      instant - Target instant
      Returns:
      ISO-8601 formatted timestamp
    • withOffset

      public static String withOffset(long amount, ChronoUnit unit)
      Generates an ISO-8601 timestamp with time offset. Example: +5 minutes, -2 hours, etc.
      Parameters:
      amount - Amount to offset
      unit - Time unit (e.g., MINUTES, HOURS)
      Returns:
      Offset timestamp in ISO-8601 format
    • text

      public static String text(Instant instant, DiscordTimeStyle style)
      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 instant
      style - Discord display style
      Returns:
      Formatted Discord timestamp string
    • relativeNow

      public static String relativeNow()
      Returns a relative timestamp for the current time. Example output: "a few seconds ago"
      Returns:
      Discord relative timestamp string