Package org.apache.zookeeper.common
Class Time
java.lang.Object
org.apache.zookeeper.common.Time
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic final intstatic final intstatic final int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic longReturns time in milliseconds as does System.currentTimeMillis(), but uses elapsed time from an arbitrary epoch more like System.nanoTime().static longExplicitly returns system dependent current wall time.static DateelapsedTimeToDate(long elapsedTime) This is to convert the elapsedTime to a Date.static StringformatTimeIntervalMs(long ms) Format milliseconds time interval with the highest time unit suffix.static intparseTimeInterval(String str) Parse a string as a time interval.
-
Field Details
-
MILLISECOND
public static final int MILLISECOND- See Also:
-
SECOND
public static final int SECOND- See Also:
-
MINUTE
public static final int MINUTE- See Also:
-
HOUR
public static final int HOUR- See Also:
-
DAY
public static final int DAY- See Also:
-
-
Constructor Details
-
Time
public Time()
-
-
Method Details
-
currentElapsedTime
public static long currentElapsedTime()Returns time in milliseconds as does System.currentTimeMillis(), but uses elapsed time from an arbitrary epoch more like System.nanoTime(). The difference is that if somebody changes the system clock, Time.currentElapsedTime will change but nanoTime won't. On the other hand, all of ZK assumes that time is measured in milliseconds.- Returns:
- The time in milliseconds from some arbitrary point in time.
-
currentWallTime
public static long currentWallTime()Explicitly returns system dependent current wall time.- Returns:
- Current time in msec.
-
elapsedTimeToDate
This is to convert the elapsedTime to a Date.- Returns:
- A date object indicated by the elapsedTime.
-
parseTimeInterval
Parse a string as a time interval. An interval is specified as an integer with an optional suffix. No suffix means milliseconds, s, m, h, d indicates seconds, minutes, hours, and days respectively. As a special case, "ms" means milliseconds.- Parameters:
str- the interval string- Returns:
- interval in milliseconds
-
formatTimeIntervalMs
Format milliseconds time interval with the highest time unit suffix.See
parseTimeInterval(String)for supported suffixes.- Parameters:
ms- milliseconds- Returns:
- string formatted with the highest time unit suffix or "0" if
msis 0
-