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

static int minutesToMillis(int minutes) {
    return (int) TimeUnit.MINUTES.toMillis(minutes);
}

From source file:Main.java

public static long getMillisecondsFromMinutes(int minutes) {
    return TimeUnit.MINUTES.toMillis(minutes);
}

From source file:Main.java

public static String milisecondsToMinuteString(long miliseconds) {
    return String.format("%d:%02d", TimeUnit.MILLISECONDS.toMinutes(miliseconds),
            TimeUnit.MILLISECONDS.toSeconds(miliseconds)
                    - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(miliseconds)));
}

From source file:Main.java

public static String getFormattedTimeInterval(long millis) {
    return String.format(Locale.US, "%02d:%02d", TimeUnit.MILLISECONDS.toMinutes(millis),
            TimeUnit.MILLISECONDS.toSeconds(millis)
                    - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millis)));
}

From source file:Main.java

public static long getDifferenceinMinutes(Date date1, Date date2) {
    System.out.println(date1.toString());

    System.out.println(date2.toString());

    if (date1 == null || date2 == null)
        return 0;

    long diff = date2.getTime() - date1.getTime();

    long diffMinutes = TimeUnit.MINUTES.convert(diff, TimeUnit.MILLISECONDS);

    return diffMinutes;
}

From source file:Main.java

public static String getHumanReadableTime(long ms) {
    final long days = TimeUnit.MILLISECONDS.toDays(ms);
    ms -= TimeUnit.DAYS.toMillis(days);
    final long hours = TimeUnit.MILLISECONDS.toHours(ms);
    ms -= TimeUnit.HOURS.toMillis(hours);
    final long minutes = TimeUnit.MILLISECONDS.toMinutes(ms);
    ms -= TimeUnit.MINUTES.toMillis(minutes);
    final long seconds = TimeUnit.MILLISECONDS.toSeconds(ms);

    final StringBuilder sb = new StringBuilder();
    sb.append(days);/*from  ww w .jav a 2  s .co  m*/
    sb.append("d ");
    sb.append(hours);
    sb.append("h ");
    sb.append(minutes);
    sb.append("m ");
    sb.append(seconds);
    sb.append('s');

    return (sb.toString());
}

From source file:Main.java

public static TimeUnit convert(ChronoUnit tu) {
    if (tu == null) {
        return null;
    }// w w  w.ja v a 2s. c  o  m
    switch (tu) {
    case DAYS:
        return TimeUnit.DAYS;
    case HOURS:
        return TimeUnit.HOURS;
    case MINUTES:
        return TimeUnit.MINUTES;
    case SECONDS:
        return TimeUnit.SECONDS;
    case MICROS:
        return TimeUnit.MICROSECONDS;
    case MILLIS:
        return TimeUnit.MILLISECONDS;
    case NANOS:
        return TimeUnit.NANOSECONDS;
    default:
        //TODO support the rest
        throw new UnsupportedOperationException("Man, use a real temporal unit");
    }
}

From source file:Main.java

/**
 * Builds String output of time in the style of: HH:MM:SS
 * @param millis/*ww w.  j a  v  a 2 s  .c o m*/
 * @return
 */
public static String buildTimerStyleTime(long millis) {
    return String.format("%02d:%02d:%02d", TimeUnit.MILLISECONDS.toHours(millis),
            TimeUnit.MILLISECONDS.toMinutes(millis)
                    - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(millis)),
            TimeUnit.MILLISECONDS.toSeconds(millis)
                    - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millis))

    );
}

From source file:Main.java

public static String getTimespentString(long millis) {

    if (millis == 0) {
        return "Undetermined";
    }/*from   w w w . j a v  a2  s  .  c om*/

    StringBuilder sb = new StringBuilder(64);

    if (millis < 0) {
        sb.append("-");
        millis *= -1;
    }

    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);

    sb.append(hours);
    sb.append(":");

    if (minutes < 10) {
        sb.append("0");
    }
    sb.append(minutes);

    return (sb.toString());
}

From source file:Main.java

private static long minutesToMillis(long minutes) {
    return TimeUnit.MINUTES.toMillis(minutes);
}