Java Utililty Methods Time Format

List of utility methods to do Time Format

Description

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

Method

StringformatTime(double totalTime)
format Time
if (totalTime > 60) {
    double mins = totalTime / 60;
    int secs = (int) totalTime % 60;
    if (mins > 60) {
        int hors = (int) (mins / 60);
        mins = mins % 60;
        int m = (int) mins;
        if (secs == 0) {
...
StringformatTime(final int timeSec)
format Time
int s = timeSec;
int m = s / 60;
s -= (m * 60);
return String.format("%02d:%02d", m, s);
StringformatTime(final long time)
format Time
long seconds = time / 1000;
final long hours = seconds / 3600;
final long minutes = (seconds % 3600) / 60;
seconds = seconds % 60;
final StringBuilder sb = new StringBuilder();
if (hours != 0) {
    sb.append(hours).append(" hours ");
if (minutes != 0) {
    sb.append(minutes).append(" minutes ");
if (seconds != 0) {
    sb.append(seconds).append(" seconds");
return sb.toString();
StringformatTime(final long time)
Formats time from long to a readable String
final int hours = (int) ((time / 1000 + 8) % 24);
final int minutes = (int) (60 * (time % 1000) / 1000);
return String.format("%02d:%02d (%d:%02d %s)", hours, minutes, hours % 12 == 0 ? 12 : hours % 12, minutes,
        hours < 12 ? "am" : "pm");
StringformatTime(final long timeMS)
Formats the time in ms to days, hours...
long remaining = timeMS / 1000;
int seconds = (int) remaining % 60;
remaining = remaining / 60;
int minutes = (int) remaining % 60;
remaining = remaining / 60;
int hours = (int) remaining % 24;
int days = (int) remaining / 24;
StringBuffer buffer = new StringBuffer();
...
StringformatTime(float seconds)
format Time
int s = (int) (seconds % 60);
int ms = (int) (seconds % 1 * 100);
int m = (int) (seconds / 60);
if (m > 0) {
    return String.format("%d:%d.%d", m, s, ms);
return String.format("%d.%d", s, ms);
StringformatTime(int minutes)
format Time
String time = "";
int hours = minutes / 60;
if (hours > 0) {
    int days = hours / 24;
    if (days > 0) {
        time += days + "d ";
    time += (hours % 24) + "h ";
...
StringformatTime(int minutes)
format Time
int hours = minutes / 60;
minutes -= hours * 60;
if (hours == 0) {
    if (minutes == 0) {
        return "Saved recently";
    } else if (minutes == 1) {
        return "Saved 1 minute ago";
    } else {
...
StringformatTime(int originalTime)
format Time
int time = originalTime;
int hours = (time - time % (60 * 60)) / 60 / 60;
String hS = "" + hours;
if (hours < 10)
    hS = "0" + hours;
time = time - (hours * 60 * 60);
int minutes = (time - time % 60) / 60;
String mS = "" + minutes;
...
StringformatTime(int seconds)
format Time
if (seconds < 0) {
    return "not set";
int hours = seconds / 3600;
int remainder = seconds % 3600;
int minutes = remainder / 60;
seconds = remainder % 60;
return String.format("%02d:%02d:%02d", hours, minutes, seconds);
...