Class TimeUtils

java.lang.Object
org.apache.camel.util.TimeUtils

public final class TimeUtils extends Object
Time utils.
  • Method Summary

    Modifier and Type
    Method
    Description
    static long
    elapsedMillisSince(long start)
    Deprecated.
    Use the Clock API when possible
    static boolean
     
    static String
    printAge(long age)
    Prints the age in a human-readable format as 9s, 27m44s, 3h12m, 3d8h, as seen on Kubernetes etc.
    static String
    printAge(long age, boolean precise)
    Prints the age in a human-readable format as 9s, 27m44s, 3h12m, 3d8h, as seen on Kubernetes etc.
    static String
    printDuration(long uptime)
    Prints the duration in a human-readable format as 9s, 27m44s, 3h12m, 3d8h, etc.
    static String
    printDuration(long uptime, boolean precise)
    Prints the duration in a human-readable format as 9s, 27m44s, 3h12m, 3d8h, etc.
    static String
    Prints the duration in a human-readable format as 9s, 27m44s, 3h12m, 3d8h, etc.
    static String
    printDuration(Duration uptime, boolean precise)
    Prints the duration in a human-readable format as 9s, 27m44s, 3h12m, 3d8h, etc.
    static String
    printSince(long time)
    Prints since age in a human-readable format as 9s, 27m44s, 3h12m, 3d8h, as seen on Kubernetes etc.
    static String
    printSince(long time, boolean precise)
    Prints since age in a human-readable format as 9s, 27m44s, 3h12m, 3d8h, as seen on Kubernetes etc.
    static Duration
    Converts to duration.
    static long
    Converts to milliseconds.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • isPositive

      public static boolean isPositive(Duration dur)
    • printSince

      public static String printSince(long time)
      Prints since age in a human-readable format as 9s, 27m44s, 3h12m, 3d8h, as seen on Kubernetes etc.
      Parameters:
      time - time of the event (millis since epoch)
      Returns:
      age in human-readable since the given time.
    • printSince

      public static String printSince(long time, boolean precise)
      Prints since age in a human-readable format as 9s, 27m44s, 3h12m, 3d8h, as seen on Kubernetes etc.
      Parameters:
      time - time of the event (millis since epoch)
      precise - whether to be precise and include more details
      Returns:
      age in human-readable since the given time.
    • printAge

      public static String printAge(long age)
      Prints the age in a human-readable format as 9s, 27m44s, 3h12m, 3d8h, as seen on Kubernetes etc.
      Parameters:
      age - age in millis
      Returns:
      age in human-readable.
    • printAge

      public static String printAge(long age, boolean precise)
      Prints the age in a human-readable format as 9s, 27m44s, 3h12m, 3d8h, as seen on Kubernetes etc.
      Parameters:
      age - age in millis
      precise - whether to be precise and include more details
      Returns:
      age in human-readable.
    • printDuration

      public static String printDuration(Duration uptime)
      Prints the duration in a human-readable format as 9s, 27m44s, 3h12m, 3d8h, etc.
      Parameters:
      uptime - the uptime in millis
      Returns:
      the time used for displaying on screen or in logs
    • printDuration

      public static String printDuration(Duration uptime, boolean precise)
      Prints the duration in a human-readable format as 9s, 27m44s, 3h12m, 3d8h, etc.
      Parameters:
      uptime - the uptime in millis
      precise - whether to be precise and include more details
      Returns:
      the time used for displaying on screen or in logs
    • printDuration

      public static String printDuration(long uptime)
      Prints the duration in a human-readable format as 9s, 27m44s, 3h12m, 3d8h, etc.
      Parameters:
      uptime - the uptime in millis
      Returns:
      the time used for displaying on screen or in logs
    • printDuration

      public static String printDuration(long uptime, boolean precise)
      Prints the duration in a human-readable format as 9s, 27m44s, 3h12m, 3d8h, etc.
      Parameters:
      uptime - the uptime in millis
      precise - whether to be precise and include more details
      Returns:
      the time used for displaying on screen or in logs
    • toDuration

      public static Duration toDuration(String source)
      Converts to duration.
      Parameters:
      source - duration which can be in text format such as 15s
    • toMilliSeconds

      public static long toMilliSeconds(String source)
      Converts to milliseconds.
      Parameters:
      source - duration which can be in text format such as 15s
      Returns:
      time in millis, will return 0 if the input is null or empty
    • elapsedMillisSince

      @Deprecated(since="4.4.0") public static long elapsedMillisSince(long start)
      Deprecated.
      Use the Clock API when possible
      Elapsed time using milliseconds since epoch.
      Parameters:
      start - the timestamp in milliseconds since epoch
      Returns:
      the elapsed time in milliseconds