Brooklyn

brooklyn.util
[Java] Class Time

java.lang.Object
  brooklyn.util.Time

public class Time

Field Summary
static java.lang.String DATE_FORMAT_PREFERRED

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

 
Method Summary
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 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. returned by System.currentTimeMillis)

static java.lang.String makeTimeString(long t, java.util.concurrent.TimeUnit unit)

given an elapsed time, makes it readable, eg 44d 6h, or 8s 923ms

static java.lang.String makeTimeString(long t)

given an elapsed time in ms, makes it readable, eg 44d 6h, or 8s 923ms

static java.lang.String makeTimeStringNano(long tn)

static java.lang.String makeTimeStringNanoLong(long tn)

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; otherwise throws Parse exception (including on null

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; otherwise throws Parse exception (including on null

static long roundFromMillis(long millis, java.util.concurrent.TimeUnit units)

static long roundFromMillis(long millis, long millisPerUnit)

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.

 
Methods inherited from class java.lang.Object
java.lang.Object#wait(), java.lang.Object#wait(long), java.lang.Object#wait(long, int), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll()
 

Field Detail

DATE_FORMAT_PREFERRED

public static java.lang.String DATE_FORMAT_PREFERRED


MILLIS_IN_DAY

public static final long MILLIS_IN_DAY


MILLIS_IN_HOUR

public static final long MILLIS_IN_HOUR


MILLIS_IN_MINUTE

public static final long MILLIS_IN_MINUTE


MILLIS_IN_SECOND

public static final long MILLIS_IN_SECOND


MILLIS_IN_YEAR

public static final long MILLIS_IN_YEAR


 
Method Detail

getTimeOfDayFromUtc

public static long getTimeOfDayFromUtc(long timeUtc)
Calculates the number of milliseconds past midnight for a given UTC time.


getTimeUtc

public 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.


makeDateString

public static java.lang.String makeDateString()
returns the current time in YYYY-MM-DD HH:MM:SS.mss format


makeDateString

public static java.lang.String makeDateString(long date)
returns the time in YYYY-MM-DD HH:MM:SS.mss format, given a long (e.g. returned by System.currentTimeMillis)


makeTimeString

public static java.lang.String makeTimeString(long t, java.util.concurrent.TimeUnit unit)
given an elapsed time, makes it readable, eg 44d 6h, or 8s 923ms


makeTimeString

public static java.lang.String makeTimeString(long t)
given an elapsed time in ms, makes it readable, eg 44d 6h, or 8s 923ms


makeTimeStringNano

public static java.lang.String makeTimeStringNano(long tn)


makeTimeStringNanoLong

public static java.lang.String makeTimeStringNanoLong(long tn)


parseTimeString

public 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; otherwise throws Parse exception (including on null


parseTimeStringAsDouble

public 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; otherwise throws Parse exception (including on null


roundFromMillis

public static long roundFromMillis(long millis, java.util.concurrent.TimeUnit units)


roundFromMillis

public static long roundFromMillis(long millis, long millisPerUnit)


sleep

public static void sleep(long millis)
sleep which propagates Interrupted as unchecked


timeRemaining

public static long timeRemaining(long startTime, long maxTime)
Calculates how long until maxTime has passed since the given startTime. However, maxTime==0 is a special case (e.g. could mean wait forever), so the result is guaranteed to be only 0 if maxTime was 0; otherwise -1 will be returned.


 

Brooklyn Multi-Cloud Application Management Platform
brooklyncentral.github.com. Apache License. © 2012.