Example usage for java.util.concurrent TimeUnit MINUTES

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

Introduction

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

Prototype

TimeUnit MINUTES

To view the source code for java.util.concurrent TimeUnit MINUTES.

Click Source Link

Document

Time unit representing sixty seconds.

Usage

From source file:Main.java

/**
 * Gets a long value i.e the time when the call was made and then returns a
 * appropriate string//from  w  w  w  .j av a 2  s.c  om
 *
 * @param callDate a long value which represents the time when the call was made
 * @return a formatted string to be displayed.
 */
public static String getTheTimePassedSinceCall(long callDate) {

    long difference = System.currentTimeMillis() - callDate;

    long diffInSeconds = getDateDiff(difference, TimeUnit.SECONDS);
    long diffInMin = getDateDiff(difference, TimeUnit.MINUTES);
    long diffInHours = getDateDiff(difference, TimeUnit.HOURS);

    return getDifferenceString(diffInSeconds, diffInMin, diffInHours, callDate);
}

From source file:Main.java

/**
 * Convert a millisecond duration to a string format
 *
 * @param millis A duration to convert to a string form
 * @return A string of the form "X Days Y Hours Z Minutes A Seconds".
 *///from  ww w  . j av a2 s.co  m
public static String getDurationBreakdown(long millis) {
    if (millis < 0) {
        throw new IllegalArgumentException("Duration must be greater than zero!");
    }

    long days = TimeUnit.MILLISECONDS.toDays(millis);
    millis -= TimeUnit.DAYS.toMillis(days);
    long hours = TimeUnit.MILLISECONDS.toHours(millis);
    millis -= TimeUnit.HOURS.toMillis(hours);
    long minutes = TimeUnit.MILLISECONDS.toMinutes(millis);
    millis -= TimeUnit.MINUTES.toMillis(minutes);
    long seconds = TimeUnit.MILLISECONDS.toSeconds(millis);

    return (String.valueOf(days) + " Days " + hours + " Hours " + minutes + " Minutes " + seconds + " Seconds");
}

From source file:Main.java

/**
 * Convert a millisecond duration to a string format
 *
 * @param millis A duration to convert to a string form
 * @return A string of the form "X Days Y Hours Z Minutes A Seconds".
 *//*from www .j a  v  a 2 s.  c  om*/
public static String getDurationBreakdownNoDays(long millis) {
    if (millis < 0) {
        throw new IllegalArgumentException("Duration must be greater than zero!");
    }

    long days = TimeUnit.MILLISECONDS.toDays(millis);
    millis -= TimeUnit.DAYS.toMillis(days);
    long hours = TimeUnit.MILLISECONDS.toHours(millis);
    millis -= TimeUnit.HOURS.toMillis(hours);
    long minutes = TimeUnit.MILLISECONDS.toMinutes(millis);
    millis -= TimeUnit.MINUTES.toMillis(minutes);
    long seconds = TimeUnit.MILLISECONDS.toSeconds(millis);

    return (hours + " Hours " + minutes + " Minutes " + seconds + " Seconds");
}

From source file:Main.java

public static String convertToReadableTime(long milliseconds, boolean includeHours) {

    if (includeHours) {
        // format hh:mm:ss
        return String.format(Locale.ENGLISH, "%02d:%02d:%02d", TimeUnit.MILLISECONDS.toHours(milliseconds),
                TimeUnit.MILLISECONDS.toMinutes(milliseconds) % TimeUnit.HOURS.toMinutes(1),
                TimeUnit.MILLISECONDS.toSeconds(milliseconds) % TimeUnit.MINUTES.toSeconds(1));
    } else if (TimeUnit.MILLISECONDS.toHours(milliseconds) < 1) {
        // format mm:ss
        return String.format(Locale.ENGLISH, "%02d:%02d",
                TimeUnit.MILLISECONDS.toMinutes(milliseconds) % TimeUnit.HOURS.toMinutes(1),
                TimeUnit.MILLISECONDS.toSeconds(milliseconds) % TimeUnit.MINUTES.toSeconds(1));
    } else {//from w ww . j av a2  s. c om
        return null;
    }

}

From source file:Main.java

public static String milliToMinutes(String milliseconds) {
    Long millis = Long.parseLong(milliseconds);
    milliseconds = String.format("%dmin : %dsec", TimeUnit.MILLISECONDS.toMinutes(millis),
            TimeUnit.MILLISECONDS.toSeconds(millis)
                    - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millis)));

    return milliseconds;
}

From source file:Dengue.CDengueManager.java

public static void schedulePolling() {
    final Runnable poller = () -> {
        loadDengueCluster();/*ww  w.j  a  v a2s .co m*/
    };

    objScheduler.scheduleAtFixedRate(poller, 0, 30, TimeUnit.MINUTES);
}

From source file:Haze.CHazeManager.java

public static void schedulePolling() {
    final Runnable poller = () -> {
        loadHazeInfo();//from  ww  w .  java2  s  .c om
    };

    objScheduler.scheduleAtFixedRate(poller, 0, 30, TimeUnit.MINUTES);
}

From source file:Main.java

public static int parseDuration(String dur) {
    if (TextUtils.isEmpty(dur))
        return 0;
    String[] strings = dur.split(":");
    if (strings.length != 3)
        return 0;
    try {/*from w  w w . j a  va  2  s  .c o m*/
        int sec = 0;
        if (!TextUtils.isEmpty(strings[0])) {
            sec += TimeUnit.SECONDS.convert(Integer.decode(strings[0]), TimeUnit.HOURS);
        }
        sec += TimeUnit.SECONDS.convert(Integer.decode(strings[1]), TimeUnit.MINUTES);
        sec += TimeUnit.SECONDS.convert(Integer.decode(strings[2].substring(0, 2)), TimeUnit.SECONDS);
        return sec;
    } catch (NumberFormatException e) {
        return 0;
    }

}

From source file:Producer.java

public synchronized void run() {
    for (int i = 0; i < 10; i++) {
        try {//  w  w w  .  j a  va  2s. co  m
            deque.offer(i, 999, TimeUnit.MINUTES);
            System.out.println(name + " puts " + i);
            Thread.sleep(300);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}

From source file:Producer.java

public synchronized void run() {
    for (int i = 0; i < 10; i++) {
        try {/* ww  w .  j a v a  2s  . c om*/
            deque.offerLast(i, 999, TimeUnit.MINUTES);
            System.out.println(name + " puts " + i);
            Thread.sleep(300);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}