Class TimeUtils

java.lang.Object
com.jeff_media.jefflib.TimeUtils

public class TimeUtils extends Object
Time related methods, like measuring time and converting nanoseconds to milliseconds, etc.
  • Field Details

  • Constructor Details

  • Method Details

    • nanoSecondsToMilliSeconds

      public static long nanoSecondsToMilliSeconds(long nanoSeconds)
      Converts nanoseconds to milliseconds
      Parameters:
      nanoSeconds - duration in nanoseconds
      Returns:
      duration in milliseconds
    • milliSecondsToTickPercentage

      public static double milliSecondsToTickPercentage(long milliSeconds)
      Converts an amount of milliseconds to tick percentage. E.g. 50 will return 100 and 25 will return 50
      Parameters:
      milliSeconds - milliseconds
      Returns:
      percentage of tick
    • formatNanoseconds

      public static String formatNanoseconds(long nanoSeconds)
      Formats nanoseconds to a human readable format in milliseconds with 4 decimal places
      Parameters:
      nanoSeconds - Duration in nanoseconds
    • nanoSecondsToMilliSecondsDouble

      public static double nanoSecondsToMilliSecondsDouble(long nanoSeconds)
      Converts nanoseconds to milliseconds, returning a double value
      Parameters:
      nanoSeconds - duration in nanoseconds
      Returns:
      duration in milliseconds
    • startTimings

      public static void startTimings(String identifier)
      Starts to record the time, using a String identifier, to be used in conjunction with endTimings(String)
      Parameters:
      identifier - Name of the task to be measured
    • endTimings

      public static long endTimings(String identifier)
      Ends the time measurement and prints out the duration in human readable milliseconds
      Parameters:
      identifier - Name of the task to be measured
      Returns:
      duration the task took in nanoseconds
    • endTimings

      public static long endTimings(String identifier, boolean sendMessage)
      Ends the time measurement, and optionally prints out the duration in human readable milliseconds
      Parameters:
      identifier - Name of the task to be measured
      Returns:
      duration the task took in nanoseconds
    • endTimings

      public static long endTimings(String identifier, @Nullable Plugin plugin, boolean sendMessage)
      Ends the time measurement and optionally prints out the duration in human readable milliseconds
      Parameters:
      identifier - Name of the mask to be measured
      plugin - Plugin of which Logger to use
      sendMessage - Whether to send a message
      Returns:
      Duration in nanoseconds
    • dateToString

      public static String dateToString(long unix)
      Converts a Unix Timestamp to a String
      Parameters:
      unix - A Unix timestamp
      Returns:
      The resulted String
    • secondsToDDHHMMSS

      public static String secondsToDDHHMMSS(long seconds)
      Converts seconds to Days, Hours, Minutes, Seconds
      Parameters:
      seconds - The given amount of seconds
      Returns:
      The resulted String
    • secondsToHHMMSS

      public static String secondsToHHMMSS(long seconds)
      Converts seconds to Hours, Minutes, Seconds
      Parameters:
      seconds - The given amount of seconds
      Returns:
      The resulted String