Android Utililty Methods Second Format

List of utility methods to do Second Format

Description

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

Method

StringformatTime(int second)
format Time
int hh = second / 3600;
int mm = second % 3600 / 60;
int ss = second % 60;
if (0 != hh) {
    return String
            .format(Locale.CHINA, "%02d:%02d:%02d", hh, mm, ss);
} else {
    return String.format(Locale.CHINA, "%02d:%02d", mm, ss);
...
StringformatTime(int second)
format Time
int hh = second / 3600;
int mm = second % 3600 / 60;
int ss = second % 60;
if (0 != hh) {
    return String.format("%02d:%02d:%02d", hh, mm, ss);
} else {
    return String.format("%02d:%02d", mm, ss);
StringformatIntoHHMMSS(int secsIn)
format Into HHMMSS
int hours = secsIn / 3600, remainder = secsIn % 3600, minutes = remainder / 60, seconds = remainder % 60;
return ((hours < 10 ? "0" : "") + hours + ":"
        + (minutes < 10 ? "0" : "") + minutes + ":"
        + (seconds < 10 ? "0" : "") + seconds);
StringgetTimeFormattedFromSeconds(int seconds)
Returns a formatted time string in the form of (hh:)mm:ss generated from seconds
return getTimeFormattedFromMillis(seconds * 1000);
StringformatElapsedTime(long elapsedSeconds)
Formats an elapsed time in the form "MM:SS" or "H:MM:SS" for display on the call-in-progress screen.
return formatElapsedTime(null, elapsedSeconds);
StringformatElapsedTime(StringBuilder recycle, long elapsedSeconds)
Formats an elapsed time in the form "MM:SS" or "H:MM:SS" for display on the call-in-progress screen.
initFormatStrings();
long hours = 0;
long minutes = 0;
long seconds = 0;
if (elapsedSeconds >= 3600) {
    hours = elapsedSeconds / 3600;
    elapsedSeconds -= hours * 3600;
if (elapsedSeconds >= 60) {
    minutes = elapsedSeconds / 60;
    elapsedSeconds -= minutes * 60;
seconds = elapsedSeconds;
String result;
if (hours > 0) {
    return formatElapsedTime(recycle, sElapsedFormatHMMSS, hours,
            minutes, seconds);
} else {
    return formatElapsedTime(recycle, sElapsedFormatMMSS, minutes,
            seconds);
StringformatElapsedTime(StringBuilder recycle, String format, long minutes, long seconds)
Fast formatting of m:ss
if (FAST_FORMAT_MMSS.equals(format)) {
    StringBuilder sb = recycle;
    if (sb == null) {
        sb = new StringBuilder(8);
    } else {
        sb.setLength(0);
    if (minutes < 10) {
...
longcurrentSeconds()
current Seconds
Calendar c = Calendar.getInstance();
long mseconds = c.getTimeInMillis();
return mseconds / 1000;
longgetInXSeconds(int seconds)
get In X Seconds
return System.currentTimeMillis() + seconds * 1000;
StringtoReadableTime(Context aContext, int aSeconds, boolean aShowSeconds)
Converts time in seconds to the readable time
StringBuilder builder = new StringBuilder();
if (aSeconds > DAY) {
    int days = aSeconds / DAY;
    String format = aContext.getResources().getString(
            R.string.utils_days, days);
    builder.append(format);
    builder.append(", ");
    aSeconds -= DAY * days;
...