Example usage for java.util.concurrent TimeUnit convert

List of usage examples for java.util.concurrent TimeUnit convert

Introduction

In this page you can find the example usage for java.util.concurrent TimeUnit convert.

Prototype

public long convert(long sourceDuration, TimeUnit sourceUnit) 

Source Link

Document

Converts the given time duration in the given unit to this unit.

Usage

From source file:Main.java

public static long getDifference(Calendar a, Calendar b, TimeUnit units) {
    return units.convert(b.getTimeInMillis() - a.getTimeInMillis(), TimeUnit.MILLISECONDS);
}

From source file:Main.java

private static int convertDelta(final long millis, TimeUnit to) {
    return (int) to.convert(System.currentTimeMillis() - millis, TimeUnit.MILLISECONDS);
}

From source file:com.relicum.ipsum.Utils.Profiler.java

public static long getCurrentDelta(String id, TimeUnit unit) {
    return unit.convert(getCurrentDelta(id), TimeUnit.NANOSECONDS);
}

From source file:com.relicum.ipsum.Utils.Profiler.java

public static long endProfiling(String id, TimeUnit unit) {
    return unit.convert(endProfiling(id), TimeUnit.NANOSECONDS);
}

From source file:Main.java

/**
 * Get a diff between two dates//from w  ww .  j a va2  s .  c  om
 *
 * @param timeUnit the unit in which you want the diff
 * @return the diff value, in the provided unit
 */
private static long getDateDiff(long diffInMillis, TimeUnit timeUnit) {
    return timeUnit.convert(diffInMillis, TimeUnit.MILLISECONDS);
}

From source file:Main.java

/**
 * Get a diff between two dates/*from  w w  w.j  av a2 s  .  c om*/
 * @param date1 the older date
 * @param date2 the newer date
 * @param timeUnit the unit in which you want the diff
 * @return the diff value, in the provided unit
 */
public static long getDateDiff(Date date1, Date date2, TimeUnit timeUnit) {
    long diffInMillis = date2.getTime() - date1.getTime();
    return timeUnit.convert(diffInMillis, TimeUnit.MILLISECONDS);
}

From source file:Main.java

/**
 * Get the difference between 2 date/time values down to millisecond
 * @param startDate/*from www . j  a  v  a 2s  .  c om*/
 * @param endDate
 * @param timeUnit
 * @return long - difference between dates based in timeUnit
 */
public static long calcTimeDifference(Date startDate, Date endDate, TimeUnit timeUnit) {

    long diffInMilliSec = endDate.getTime() - startDate.getTime();
    return timeUnit.convert(diffInMilliSec, timeUnit);
}

From source file:gobblin.data.management.retention.sql.SqlUdfs.java

private static long date_diff(long timestamp1, long timestamp2, String unitString) {

    try {//from  w  w w .  j  a v a  2 s  . c  om
        TimeUnit unit = TimeUnit.valueOf(TimeUnit.class, StringUtils.upperCase(unitString));
        return unit.convert(timestamp1 - timestamp2, TimeUnit.MILLISECONDS);
    } catch (IllegalArgumentException e) {
        log.error("Valid input for unitString is java.util.concurrent.TimeUnit", e);
    }

    return 0l;
}

From source file:org.openmrs.module.openconceptlab.Utils.java

/**
 * Difference between two dates//from www.  j  a v  a2 s  .co m
 * @return duration
 */
public static Long dateDifference(Date date1, Date date2, TimeUnit timeUnit) {
    long diffInMillies = date2.getTime() - date1.getTime();
    return timeUnit.convert(diffInMillies, TimeUnit.MILLISECONDS);
}

From source file:org.janusgraph.testutil.TestGraphConfigs.java

public static long getTTL(TimeUnit u) {
    final long sec = 10L;
    long l = u.convert(sec, TimeUnit.SECONDS);
    // Check that a narrowing cast to int will not overflow, in case a test decides to try it.
    Preconditions.checkState(Integer.MIN_VALUE <= l && Integer.MAX_VALUE >= l,
            "Test TTL %d is too large to express as an integer in %s", sec, u);
    return l;/*from   w ww .  j  ava 2s . c  o  m*/
}