Java tutorial
//package com.java2s; //License from project: Open Source License import android.util.Log; import java.util.Locale; public class Main { private static final String TAG = "Helper"; /** * Converts time to a string, e.g. "1:59:30" * or "3.6" or "5:33". * * @param milliseconds Time in milliseconds since start of meeting * @return String formatted time interval string in "H:MM:SS" format. */ public static String timeToHMMSS(long milliseconds) { Log.v(TAG, "timeToHMMSS(" + milliseconds + ")"); int seconds = (int) (milliseconds % 60_000) / 1000; int minutes = (int) (milliseconds / 60_000) % 60; int hours = (int) (milliseconds / 3600_000); String hms; if (hours >= 1) { hms = String.format(Locale.getDefault(), "%d:%02d:%02d", hours, minutes, seconds); } else if (minutes >= 1) { hms = String.format(Locale.getDefault(), "%d:%02d", minutes, seconds); } else { hms = String.format(Locale.getDefault(), "%d", seconds); } return hms; } }