public class Time
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
DATE_FORMAT_PREFERRED |
static java.lang.String |
DATE_FORMAT_STAMP |
static long |
MILLIS_IN_DAY |
static long |
MILLIS_IN_HOUR |
static long |
MILLIS_IN_MINUTE |
static long |
MILLIS_IN_SECOND |
static long |
MILLIS_IN_YEAR |
Constructor and Description |
---|
Time() |
Modifier and Type | Method and Description |
---|---|
static java.util.Date |
dropMilliseconds(java.util.Date date)
removes milliseconds from the date object; needed if serializing to ISO-8601 format
and want to serialize back and get the same data
|
static Duration |
elapsedSince(long timestamp)
returns the duration elapsed since the given timestamp (UTC)
|
static com.google.common.base.Function<Duration,java.lang.String> |
fromDurationToTimeStringRounded() |
static com.google.common.base.Function<java.lang.Long,java.lang.String> |
fromLongToTimeStringExact() |
static com.google.common.base.Function<java.lang.Long,java.lang.String> |
fromLongToTimeStringRounded() |
static long |
getTimeOfDayFromUtc(long timeUtc)
Calculates the number of milliseconds past midnight for a given UTC time.
|
static long |
getTimeUtc(java.util.TimeZone zone,
int year,
int month,
int date,
int hourOfDay,
int minute,
int second,
int millis)
Calculates the number of milliseconds past epoch for a given UTC time.
|
static boolean |
hasElapsedSince(long timestamp,
Duration duration)
true iff it has been longer than the given duration since the given timestamp
|
static java.lang.String |
makeDateStampString()
returns the current time in YYYYMMDD-HHMMSSmss format
|
static java.lang.String |
makeDateStampString(long date)
returns the time in YYYY-MM-DD HH:MM:SS.mss format, given a long (e.g.
|
static java.lang.String |
makeDateString()
returns the current time in YYYY-MM-DD HH:MM:SS.mss format
|
static java.lang.String |
makeDateString(long date)
returns the time in YYYY-MM-DD HH:MM:SS.mss format, given a long (e.g.
|
static java.lang.String |
makeTimeString(long t,
boolean round)
given an elapsed time, makes it readable, eg 44d 6h, or 8s 923ms, optionally rounding
|
static java.lang.String |
makeTimeStringExact(Duration d) |
static java.lang.String |
makeTimeStringExact(long t) |
static java.lang.String |
makeTimeStringExact(long t,
java.util.concurrent.TimeUnit unit) |
static java.lang.String |
makeTimeStringNano(long tn,
boolean round) |
static java.lang.String |
makeTimeStringNanoExact(long tn) |
static java.lang.String |
makeTimeStringNanoRounded(long tn) |
static java.lang.String |
makeTimeStringRounded(Duration d) |
static java.lang.String |
makeTimeStringRounded(long t) |
static java.lang.String |
makeTimeStringRounded(long t,
java.util.concurrent.TimeUnit unit) |
static java.lang.String |
makeTimeStringRounded(com.google.common.base.Stopwatch timer) |
static java.lang.String |
makeTimeStringRoundedSince(long utc) |
static long |
now()
more readable and shorter convenience for System.currentTimeMillis()
|
static java.util.Date |
parseDateString(java.lang.String dateString,
java.text.DateFormat format)
Parses the given date, accepting either a UTC timestamp (i.e.
|
static long |
parseTimeString(java.lang.String timeString)
parses a string eg '5s' or '20m 22.123ms', returning the number of milliseconds it represents (rounded);
-1 on blank or "never" or "off" or "false";
number of millis if no units specified.
|
static double |
parseTimeStringAsDouble(java.lang.String timeString)
parses a string eg '5s' or '20m 22.123ms', returning the number of milliseconds it represents; -1 on blank or never or off or false;
number of millis if no units specified.
|
static long |
roundFromMillis(long millis,
long millisPerUnit) |
static long |
roundFromMillis(long millis,
java.util.concurrent.TimeUnit units) |
static void |
sleep(Duration duration)
as
sleep(long) |
static void |
sleep(long millis)
sleep which propagates Interrupted as unchecked
|
static long |
timeRemaining(long startTime,
long maxTime)
Calculates how long until maxTime has passed since the given startTime.
|
static com.google.common.base.Function<java.lang.Long,java.lang.String> |
toDateStampString() |
static com.google.common.base.Function<java.lang.Long,java.lang.String> |
toDateString() |
static com.google.common.base.Function<java.lang.Long,java.lang.String> |
toTimeString()
Deprecated.
since 0.7.0 use
fromLongToTimeStringExact() |
static com.google.common.base.Function<java.lang.Long,java.lang.String> |
toTimeStringRounded()
Deprecated.
since 0.7.0 use
fromLongToTimeStringRounded() |
public static final java.lang.String DATE_FORMAT_PREFERRED
public static final java.lang.String DATE_FORMAT_STAMP
public static final long MILLIS_IN_SECOND
public static final long MILLIS_IN_MINUTE
public static final long MILLIS_IN_HOUR
public static final long MILLIS_IN_DAY
public static final long MILLIS_IN_YEAR
public static java.lang.String makeDateString()
public static java.lang.String makeDateString(long date)
public static com.google.common.base.Function<java.lang.Long,java.lang.String> toDateString()
public static java.lang.String makeDateStampString()
public static java.lang.String makeDateStampString(long date)
public static com.google.common.base.Function<java.lang.Long,java.lang.String> toDateStampString()
public static java.lang.String makeTimeStringExact(long t, java.util.concurrent.TimeUnit unit)
makeTimeString(long, boolean)
public static java.lang.String makeTimeStringRounded(long t, java.util.concurrent.TimeUnit unit)
makeTimeString(long, boolean)
public static java.lang.String makeTimeStringRounded(com.google.common.base.Stopwatch timer)
public static java.lang.String makeTimeStringExact(long t)
makeTimeString(long, boolean)
public static java.lang.String makeTimeStringRounded(long t)
makeTimeString(long, boolean)
public static java.lang.String makeTimeStringRoundedSince(long utc)
makeTimeString(long, boolean)
public static java.lang.String makeTimeStringExact(Duration d)
makeTimeString(long, boolean)
public static java.lang.String makeTimeStringRounded(Duration d)
makeTimeString(long, boolean)
public static java.lang.String makeTimeString(long t, boolean round)
public static java.lang.String makeTimeStringNanoExact(long tn)
makeTimeString(long, boolean)
public static java.lang.String makeTimeStringNanoRounded(long tn)
makeTimeString(long, boolean)
public static java.lang.String makeTimeStringNano(long tn, boolean round)
makeTimeString(long, boolean)
public static com.google.common.base.Function<java.lang.Long,java.lang.String> fromLongToTimeStringExact()
@Deprecated public static com.google.common.base.Function<java.lang.Long,java.lang.String> toTimeString()
fromLongToTimeStringExact()
public static com.google.common.base.Function<java.lang.Long,java.lang.String> fromLongToTimeStringRounded()
@Deprecated public static com.google.common.base.Function<java.lang.Long,java.lang.String> toTimeStringRounded()
fromLongToTimeStringRounded()
public static com.google.common.base.Function<Duration,java.lang.String> fromDurationToTimeStringRounded()
public static void sleep(long millis)
public static void sleep(Duration duration)
sleep(long)
public static long getTimeOfDayFromUtc(long timeUtc)
public static long getTimeUtc(java.util.TimeZone zone, int year, int month, int date, int hourOfDay, int minute, int second, int millis)
public static long roundFromMillis(long millis, java.util.concurrent.TimeUnit units)
public static long roundFromMillis(long millis, long millisPerUnit)
public static long timeRemaining(long startTime, long maxTime)
public static long parseTimeString(java.lang.String timeString)
java.lang.NumberFormatException
- if cannot be parsed (or if null)public static double parseTimeStringAsDouble(java.lang.String timeString)
java.lang.NumberFormatException
- if cannot be parsed (or if null)public static java.util.Date parseDateString(java.lang.String dateString, java.text.DateFormat format)
dateString
- format
- public static java.util.Date dropMilliseconds(java.util.Date date)
public static Duration elapsedSince(long timestamp)
public static boolean hasElapsedSince(long timestamp, Duration duration)
public static long now()