Here you can find the source of formatTimeInterval(long in)
Parameter | Description |
---|---|
in | positive interval millisec |
public static String formatTimeInterval(long in)
//package com.java2s; //License from project: Apache License public class Main { /**//from w w w .ja v a 2 s . c o m * return a string a time interval in millisec * @param in positive interval millisec * @returb non-null string i.e. 3:40 */ public static String formatTimeInterval(long in) { int del = (int) (in + 500) / 1000; // drop millisec int seconds = del % 60; del /= 60; int minute = del % 60; del /= 60; int hour = del % 24; del /= 24; int days = del; StringBuffer holder = new StringBuffer(); if (days != 0) { holder.append(Integer.toString(days)); holder.append(":"); holder.append(d02(hour)); holder.append(":"); holder.append(d02(minute)); holder.append(":"); holder.append(d02(seconds)); } else { if (hour != 0) { holder.append(Integer.toString(hour)); holder.append(":"); holder.append(d02(minute)); holder.append(":"); holder.append(d02(seconds)); } else { holder.append(d02(minute)); holder.append(":"); holder.append(d02(seconds)); } } return (holder.toString()); } /**{ method @name toString @function convert a char to a string @param c the char @return the String }*/ public static String toString(char c) { StringBuffer s = new StringBuffer(); s.append(c); return (s.toString()); } /** * convert a 2 digit int to 00 , 02 or 12 * in integer between 0 and 99 * @return non-null string */ protected static String d02(int in) { if (in == 0) { return ("00"); } else { if (in < 10) { return ("0" + in); } return (Integer.toString(in)); } } }