Class TimeUtils

java.lang.Object
org.kingdoms.utils.time.TimeUtils

public final class TimeUtils extends Object
  • Field Details

  • Constructor Details

    • TimeUtils

      public TimeUtils()
  • Method Details

    • validateUnixTime

      public static void validateUnixTime(long time)
    • getDateAndTime

      @Nonnull public static StringBuilder getDateAndTime(TemporalAccessor accessor)
      Gets the current full time.
      Returns:
      current time with the format of yyyy/MM/dd hh:mm:ss
      Since:
      1.0.0
    • formatTime

      @Nonnull public static StringBuilder formatTime(DateTimeFormatter formatter, TemporalAccessor accessor, int buffer)
    • getDateAndTime

      @Nonnull public static StringBuilder getDateAndTime(long epoch)
    • now

      @Nonnull public static ZonedDateTime now()
    • epoch

      @Nonnull @Pure public static ZonedDateTime epoch()
    • getDateAndTime

      @Nonnull public static StringBuilder getDateAndTime()
    • getTime

      @Nonnull public static StringBuilder getTime()
      Gets the current time.
      Returns:
      current time with the format of hh:mm:ss
      Since:
      1.0.0
    • getTime

      @Nonnull public static StringBuilder getTime(TemporalAccessor accessor)
    • getTime

      @Nonnull public static StringBuilder getTime(long epoch)
    • afterNow

      public static long afterNow(Duration duration)
    • getDate

      @Nonnull public static StringBuilder getDate(long epoch)
    • getDate

      @Nonnull public static StringBuilder getDate(TemporalAccessor accessor)
    • getDate

      @Nonnull public static StringBuilder getDate()
    • getTimeUntil

      public static long getTimeUntil(CharSequence time, String timeZone, ChronoUnit timeUnit)
      Gets the time difference between the current time and the specified time using the argument time unit.
      Parameters:
      time - the local time to parse.
      timeZone - the time zone from https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
      Returns:
      ticks until the specified time.
    • getTimeUntilTomrrow

      public static Duration getTimeUntilTomrrow(ZoneId timezone)
    • parseTime

      public static Long parseTime(String time)
    • parseTime

      public static Long parseTime(String time, TimeUnit timeUnit)
      Calculate a time in a form of a string. Supports days to milliseconds.
      Acts exactly like the RegEx expression (\d+)(\S*)
      Parameters:
      time - the string time with its unit.
      Returns:
      the parsed milliseconds from the time unit.
    • millisToTicks

      public static long millisToTicks(long millis)
      A gametick is where Minecraft's game loop runs once. The game normally runs at a fixed rate of 20 ticks per second, so one tick happens every 0.05 seconds (50 milliseconds, or five hundredths of a second), making an in-game day lasts exactly 24000 ticks, or 20 minutes.
      Parameters:
      millis - the milliseconds.
      Returns:
      game ticks with -1 ticks error.
    • toTicks

      public static long toTicks(Duration duration)