Android Utililty Methods Second to Time

List of utility methods to do Second to Time

Description

The list of methods to do Second to Time are organized into topic(s).

Method

StringconvertSecondsToTimeStamp(int seconds)
convert Seconds To Time Stamp
String hours = Integer.toString(seconds / 3600);
if (hours.length() == 1) {
    hours = '0' + hours;
String minutes = Integer.toString((seconds % 3600) / 60);
if (minutes.length() == 1) {
    minutes = '0' + minutes;
String secondsStr = Integer.toString(seconds % 60);
if (secondsStr.length() == 1) {
    secondsStr = '0' + secondsStr;
return hours + ":" + minutes + ":" + secondsStr;
StringsecsToText(long time)
Converts a number of seconds to a String in the format 00:00
return String.format(Locale.US, "%02d:%02d", time / 60, time % 60);
int[]calculateDhms(int seconds)
calculate Dhms
final int day = seconds / 86400;
final int hour = seconds % 86400 / 3600;
final int minute = seconds % 86400 % 3600 / 60;
final int second = seconds % 86400 % 3600 % 60;
return new int[] { day, hour, minute, second };
StringsecondsToString(int seconds)
Converts seconds to string, format mm:ss e.g.
String s = "" + seconds / 60 + ":";
int t = seconds % 60;
s += t < 10 ? "0" + t : t;
return s;
StringintSecondsToStringMinSec(int input)
int Seconds To String Min Sec
DecimalFormat df = new DecimalFormat("#00");
int m, s;
m = input / 60;
s = input % 60;
String tmp = new String();
tmp = df.format(m) + ":" + df.format(s);
return tmp;
StringgetTimeRemaining(long durationInMilliseconds)
get Time Remaining
SimpleDateFormat sdf;
if (durationInMilliseconds > 1000 * 60 * 60) {
    sdf = new SimpleDateFormat("HH:mm", Locale.getDefault());
} else {
    sdf = new SimpleDateFormat("mm:ss", Locale.getDefault());
return sdf.format(new Date(durationInMilliseconds
        - TimeZone.getDefault().getRawOffset()));
...
booleantimeRemaining(double seconds)
Controls a while-loop for a specific number of seconds.
if (_newCountDown) {
    _startTime = System.currentTimeMillis();
    _newCountDown = false;
if (System.currentTimeMillis() <= _startTime + seconds * 1000)
    return true;
else {
    _newCountDown = true;
...
longgetDfferenceInMinute(long miliseconds)
This method used to get difference from minute.
long diff = (Calendar.getInstance().getTimeInMillis() - miliseconds);
diff = diff / 60000L;
return Math.abs(diff);
StringgetTimeForm(long milliseconds)
get Time Form
Calendar c = Calendar.getInstance();
c.setTimeInMillis(milliseconds);
StringBuffer sb = new StringBuffer();
sb.append(c.get(Calendar.YEAR)).append("-")
        .append(c.get(Calendar.MONTH) + 1).append("-")
        .append(c.get(Calendar.DAY_OF_MONTH)).append(" ")
        .append(c.get(Calendar.HOUR_OF_DAY)).append(":")
        .append(c.get(Calendar.MINUTE));
...
StringmilliSecondsToTimer(long milliseconds)
milli Seconds To Timer
String totalTime = "";
String totalSeconds = "";
String totalMinutes = "";
int hours = (int) (milliseconds / (1000 * 60 * 60));
int minutes = (int) (milliseconds % (1000 * 60 * 60)) / (1000 * 60);
int seconds = (int) ((milliseconds % (1000 * 60 * 60))
        % (1000 * 60) / 1000);
if (hours > 0) {
...