List of usage examples for java.util.concurrent TimeUnit toMinutes
public long toMinutes(long duration)
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: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 ww w .j a va 2 s . c om @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(); }