Java - Write code to get Formatted Time from second in double

Requirements

Write code to get Formatted Time from second in double

Demo

//package com.book2s;
import java.util.Formatter;

public class Main {
    public static void main(String[] argv) {
        double timeInSeconds = 42.45678;
        System.out.println(getFormattedTime(timeInSeconds));
    }/* www . j av a 2s  .  c  o m*/

    public static String getFormattedTime(double timeInSeconds) {
        int intTime = (int) timeInSeconds;
        final int hours = intTime / 3600;
        intTime = intTime % 3600;
        final int min = intTime / 60;
        intTime = intTime % 60;
        final StringBuilder stringBuilder = new StringBuilder();
        final Formatter formatter = new Formatter(stringBuilder);
        formatter.format("%02d:%02d:%02d", hours, min, intTime);
        formatter.close();
        return stringBuilder.toString();
    }
}

Related Exercise