Class TimeUtil

java.lang.Object
com.kamikazejam.kamicommon.util.TimeUtil

public class TimeUtil extends Object
  • Constructor Details

    • TimeUtil

      public TimeUtil()
  • Method Details

    • getSecondsToTimeString

      @NotNull public static @NotNull String getSecondsToTimeString(long seconds)
      Compiles current duration in the TimeUtil.TimeFormat.LETTERS format:
      "2d, 10h, 5m, 3s" when days > 0
      "10h, 5m, 3s" when hours > 0
      "5m, 3s" when minutes > 0
      "3s" when seconds > 0
    • getSecondsToTimeString

      @NotNull public static @NotNull String getSecondsToTimeString(long seconds, @NotNull @NotNull TimeUtil.TimeFormat format)
      Returns the current time in the following formats:

      TimeUtil.TimeFormat.LETTERS
      "2d, 10h, 5m, 3s" when days > 0
      "10h, 5m, 3s" when hours > 0
      "5m, 3s" when minutes > 0
      "3s" when seconds > 0

      TimeUtil.TimeFormat.WORDS
      "2 days, 10 hours, 5 minutes, 3 seconds" when days > 0
      "10 hours, 5 minutes, 3 seconds" when hours > 0
      "5 minutes, 3 seconds" when minutes > 0
      "3 seconds" when seconds > 0
      (The time word only includes the plural "s" when appropriate)
    • getDateBy24HourTime

      @NotNull public static @NotNull Date getDateBy24HourTime(@NotNull @NotNull String clockTime, @NotNull @NotNull TimeZone timeZone) throws IllegalArgumentException
      Parameters:
      clockTime - A 24-hour time string formatted like "HH:mm" or "HH:mm:ss"
      timeZone - The time zone to use
      Returns:
      a Date object representing that time of day in the nearest future
      Throws:
      IllegalArgumentException
    • getDateBy24HourTime

      @NotNull public static @NotNull Date getDateBy24HourTime(int hour, int minute, int second, @NotNull @NotNull TimeZone timeZone)
      Parameters:
      hour - The 24-hour time hour [0, 23]
      minute - The minute, [0, 59]
      second - The second, [0, 59]
      timeZone - The time zone to use
      Returns:
      a Date object representing that time of day in the nearest future