Class Time

java.lang.Object
org.apache.hadoop.util.Time

@LimitedPrivate({"HDFS","MapReduce"}) @Unstable public final class Time extends Object
Utility methods for getting the time and computing intervals.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    formatTime(long millis)
    Convert time in millisecond to human readable format.
    static long
    Get the current UTC time in milliseconds.
    static long
    Current time from some arbitrary time base in the past, counting in milliseconds, and not affected by settimeofday or similar system clock changes.
    static long
    Same as monotonicNow() but returns its result in nanoseconds.
    static long
    now()
    Current system time.

    Methods inherited from class java.lang.Object

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

    • Time

      public Time()
  • Method Details

    • now

      public static long now()
      Current system time. Do not use this to calculate a duration or interval to sleep, because it will be broken by settimeofday. Instead, use monotonicNow.
      Returns:
      current time in msec.
    • monotonicNow

      public static long monotonicNow()
      Current time from some arbitrary time base in the past, counting in milliseconds, and not affected by settimeofday or similar system clock changes. This is appropriate to use when computing how much longer to wait for an interval to expire. This function can return a negative value and it must be handled correctly by callers. See the documentation of System#nanoTime for caveats.
      Returns:
      a monotonic clock that counts in milliseconds.
    • monotonicNowNanos

      public static long monotonicNowNanos()
      Same as monotonicNow() but returns its result in nanoseconds. Note that this is subject to the same resolution constraints as System.nanoTime().
      Returns:
      a monotonic clock that counts in nanoseconds.
    • formatTime

      public static String formatTime(long millis)
      Convert time in millisecond to human readable format.
      Parameters:
      millis - millisecond.
      Returns:
      a human readable string for the input time
    • getUtcTime

      public static long getUtcTime()
      Get the current UTC time in milliseconds.
      Returns:
      the current UTC time in milliseconds.