Java examples for java.util:Second
Seconds to Time
//package com.java2s; public class Main { public static void main(String[] argv) throws Exception { double totalSeconds = 2.45678; System.out.println(toTime(totalSeconds)); }// w w w . jav a 2s . c o m /** * * @param totalSeconds * @return a human readeable time */ public static String toTime(double totalSeconds) { int hours = (int) (totalSeconds / 3600.0D); int minutes = (int) (totalSeconds % 3600) / 60; int seconds = (int) (totalSeconds % 60.0D); return toDoubleDigit(hours) + ":" + toDoubleDigit(minutes) + ":" + toDoubleDigit(seconds); } /** * * @param paramInt * @return */ public static String toDoubleDigit(int paramInt) { if (Math.abs(paramInt) < 10) { return ("0" + paramInt); } return "" + paramInt; } }