Java Utililty Methods TimeUnit Usage

List of utility methods to do TimeUnit Usage

Description

The list of methods to do TimeUnit Usage are organized into topic(s).

Method

ArrayList>getAllCombinations(ArrayList lengths)
Given a vector of sizes, every possible combination consisting of one member from each groups of a given size is returned.
long start = System.currentTimeMillis();
ArrayList<ArrayList<Integer>> combos = new ArrayList<ArrayList<Integer>>();
getAllCombinations(lengths, 0, new ArrayList<Integer>(lengths.size()), combos);
System.out.println(combos.size() + " combinations of length " + combos.get(0).size());
long end = System.currentTimeMillis();
System.out.println("Combination computation time: " + TimeUnit.MILLISECONDS.toMinutes(end - start)
        + " minutes (" + (end - start) + " milliseconds)");
return combos;
...
longgetAllDaysCount(final long milliseconds)
get All Days Count
return milliseconds / DATE;
longgetBookingDays(Calendar start, Calendar end)
Returns the entire number of business booking days between two given dates
long diff = end.getTime().getTime() - start.getTime().getTime();
return TimeUnit.DAYS.convert(diff, TimeUnit.MILLISECONDS) + 1;
DategetCurrentDateTime(int offsetMin)
get Current Date Time
return new Date(System.currentTimeMillis() + TimeUnit.MINUTES.toMillis(offsetMin));
longgetCurrentTimeMillis()
Gets the current time in milliseconds, converting from the nanoseconds returned by System#nanoTime() with TimeUnit#convert(long,TimeUnit)
return TimeUnit.MILLISECONDS.convert(System.nanoTime(), TimeUnit.NANOSECONDS);
longgetCurrentTimestamp()
get Current Timestamp
return TimeUnit.SECONDS.convert(Calendar.getInstance().getTimeInMillis(), TimeUnit.MILLISECONDS);
longgetCurrentTimestampInSeconds()
Get current time in seconds.
return TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis());
DategetDate(final int oceanTime)
Convert the specified Ocean time to a Java Date .
return new Date(TimeUnit.MILLISECONDS.convert(((long) oceanTime) + NO_SECONDS_1970_1980, TimeUnit.SECONDS));
DategetDateBefore(final Date day)
get Date Before
final Calendar c = Calendar.getInstance();
c.setTime(day);
final int day1 = c.get(Calendar.DATE);
c.set(Calendar.DATE, day1 - 1);
return c.getTime();
DategetDateWithoutTime(final Calendar calendar)
get Date Without Time
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
return calendar.getTime();