Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.concurrent.TimeUnit;

public class Main {
    public static String getTimespentString(long millis) {

        if (millis == 0) {
            return "Undetermined";
        }

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