Example usage for java.util.concurrent TimeUnit toDays

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

Introduction

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

Prototype

public long toDays(long duration) 

Source Link

Document

Equivalent to #convert(long,TimeUnit) DAYS.convert(duration, this) .

Usage

From source file:TimeUnitDemo.java

public static void main(String[] args) {
    TimeUnit tu = TimeUnit.DAYS;

    System.out.println(tu.toDays(1));
    System.out.println(tu.toHours(1));
    System.out.println(tu.toMinutes(1));

}

From source file:Main.java

public static void main(String[] args) {
    TimeUnit tu = TimeUnit.DAYS;

    System.out.println(tu.toDays(1));
    System.out.println(tu.toHours(1));
    System.out.println(tu.toMillis(1));

}

From source file:Main.java

public static void main(String[] args) {
    TimeUnit tu = TimeUnit.DAYS;

    System.out.println(tu.toDays(1));
    System.out.println(tu.toHours(1));
    System.out.println(tu.toNanos(1));

}

From source file:Main.java

public static void main(String[] args) {
    TimeUnit tu = TimeUnit.DAYS;

    System.out.println(tu.toDays(1));
    System.out.println(tu.toHours(1));
    System.out.println(tu.toMicros(1));

}

From source file:Main.java

public static void main(String[] args) {
    TimeUnit tu = TimeUnit.DAYS;

    System.out.println(tu.toDays(1));
    System.out.println(tu.toHours(1));
    System.out.println(tu.toSeconds(1));

}

From source file:com.brightcove.player.samples.offlineplayback.VideoListAdapter.java

/**
 * Converts the given duration into a time span string.
 *
 * @param duration elapsed time as number of milliseconds.
 * @return the formatted time span string.
 *//*from www . j a v  a  2s .  c  o  m*/
@NonNull
public static String millisecondsToString(long duration) {
    final TimeUnit scale = TimeUnit.MILLISECONDS;

    StringBuilder builder = new StringBuilder();
    long days = scale.toDays(duration);
    duration -= TimeUnit.DAYS.toMillis(days);
    if (days > 0) {
        builder.append(days);
        builder.append(days > 1 ? " days " : " day ");
    }

    long hours = scale.toHours(duration);
    duration -= TimeUnit.HOURS.toMillis(hours);
    if (hours > 0) {
        builder.append(String.format("%02d:", hours));
    }

    long minutes = scale.toMinutes(duration);
    duration -= TimeUnit.MINUTES.toMillis(minutes);

    long seconds = scale.toSeconds(duration);
    builder.append(String.format("%02d:%02d", minutes, seconds));

    return builder.toString();
}