Here you can find the source of getFormattedTimeString(double s)
public static String getFormattedTimeString(double s)
//package com.java2s; //License from project: Open Source License import java.text.DecimalFormat; public class Main { private static DecimalFormat fmt = new DecimalFormat("##.###"); public static String getFormattedTimeString(double s) { int hours = (int) s; // 10 ok int minutes = (int) ((s - hours) * 60); // 53 ok // int seconds = (int) ((MTC - hours) * 3600 - minutes * 60 + 0.5); // 24 ok // double seconds = Math.round(10.0*((s - hours) * 3600 - minutes * 60))/10.0; // 24 ok double seconds = (s - hours) * 3600 - minutes * 60; // 24 ok if (s < 0) { minutes = -minutes;/* w w w. ja v a 2 s. co m*/ String ss = null; if (seconds < 10) { ss = "0" + fmt.format(-seconds); } else { ss = fmt.format(-seconds); } if (hours == 0) { return String.format("-%02d:%02d:", hours, minutes) + ss; } // else { // } } String ss = null; if (seconds < 10) { ss = "0" + fmt.format(seconds); } else { ss = fmt.format(seconds); } return String.format("%02d:%02d:", hours, minutes) + ss; } }