List of utility methods to do TimeUnit Usage
int | randomNanos(Random rand, int decimalDigits) random Nanos int nanos = rand.nextInt((int) NANOSECONDS_PER_SECOND); return nanos - nanos % (int) Math.pow(10, 9 - decimalDigits); |
List | rangeOf(final Date date, final int beforeDates, final int afterDates) range Of final Calendar c = Calendar.getInstance(); c.setTime(date); final int size = beforeDates + afterDates + 1; final List<Date> list = Arrays.asList(new Date[size]); list.set(beforeDates, date); for (int i = beforeDates; i > 0;) { c.add(Calendar.DATE, -1); list.set(--i, c.getTime()); ... |
long | roundTimestampToNexDay(long timestamp) round Timestamp To Nex Day return roundTimestampToDay(timestamp) + TimeUnit.DAYS.toMillis(1);
|
T | run(Callable run FutureTask<T> future = new FutureTask<T>(task); new Thread(future).start(); T r = null; try { r = future.get(timeout, TimeUnit.MILLISECONDS); } finally { try { future.cancel(true); ... |
void | second(long second) second try { TimeUnit.SECONDS.sleep(second); } catch (InterruptedException e) { e.printStackTrace(); |
long | seconds(long timeInMillis) seconds return TimeUnit.MILLISECONDS.toSeconds(timeInMillis);
|
long | secondsFromNow(long seconds) seconds From Now return System.currentTimeMillis() + toMillis(seconds, TimeUnit.SECONDS);
|
int | secondsPassed(int startTime) seconds Passed return getSecondsTimeStamp() - startTime;
|
String | secondsToETA(long secondsTotal) seconds To ETA long hours = TimeUnit.SECONDS.toHours(secondsTotal); long minutes = TimeUnit.SECONDS.toMinutes(secondsTotal) - TimeUnit.HOURS.toMinutes(TimeUnit.SECONDS.toHours(secondsTotal)); long seconds = secondsTotal - TimeUnit.MINUTES.toSeconds(TimeUnit.SECONDS.toMinutes(secondsTotal)); String str; if (hours > 0) { str = String.format("%02d:%02d:%02ds", hours, minutes, seconds); } else if (minutes > 0) { ... |
String | secondsToHMS(long seconds) Show time in seconds as hours, minutes and seconds (hh:mm:ss) long hours = TimeUnit.SECONDS.toHours(seconds); long minutes = TimeUnit.SECONDS.toMinutes(seconds) % TimeUnit.HOURS.toMinutes(1); seconds = TimeUnit.SECONDS.toSeconds(seconds) % TimeUnit.MINUTES.toSeconds(1); return String.format("%02d:%02d:%02d", hours, minutes, seconds); |