Here you can find the source of getDHMS(long totalSecond)
Parameter | Description |
---|---|
totalSecond | of seconds |
public static String getDHMS(long totalSecond)
//package com.java2s; /*//from www . j a v a 2 s. c o m * License information at https://github.com/Caltech-IPAC/firefly/blob/master/License.txt */ import java.text.DecimalFormat; public class Main { /** * Get a String in HH:MM:SS format for a gievn total seconds (float) * total seconds = hour*3600 + minute*60 +seconds, Michael Nguyen * @param totalSecond of seconds * @return String */ public static String getDHMS(long totalSecond) { String time = "00:00:00"; if (totalSecond > 0) { String dayStr = ""; long days = totalSecond / (3600 * 24); if (days > 0) { dayStr = days + " days "; totalSecond -= (3600 * 24); } DecimalFormat decimalFormat = new DecimalFormat("00"); long hour = totalSecond / 3600; if (hour > 0) time = decimalFormat.format(hour); else time = "00"; time += ":"; long minute = (totalSecond - (hour * 3600)) / 60; if (minute > 0) time += decimalFormat.format(minute); else time += "00"; time += ":"; long second = totalSecond - (hour * 3600) - (minute * 60); if (second > 0) time += decimalFormat.format(second); else time += "00"; return dayStr + time; } else { return time; } } }