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

StringformatTimeDiff(long finishTime, long startTime)
Given a finish and start time in long milliseconds, returns a String in the format Xhrs, Ymins, Z sec, for the time difference between two times.
long timeDiff = finishTime - startTime;
return formatTime(timeDiff);
StringformatTimeDiff(long finishTime, long startTime)
Given a finish and start time in long milliseconds, returns a String in the format Xhrs, Ymins, Z sec, for the time difference between two times.
StringBuffer buf = new StringBuffer();
long timeDiff = finishTime - startTime;
long hours = timeDiff / (60 * 60 * 1000);
long rem = (timeDiff % (60 * 60 * 1000));
long minutes = rem / (60 * 1000);
rem = rem % (60 * 1000);
long seconds = rem / 1000;
if (hours != 0) {
...
StringformatTimeDifference(long ms)
format Time Difference
if (ms < 1000) {
    return "< 1 second";
long seconds = ms / 1000;
if (seconds < 60) {
    return ((int) seconds) + " seconds";
int minutes = (int) seconds / 60;
...
StringformatTimeDifference(long time1, long time2)
format Time Difference
return formatTime(getTimeDifference(time1, time2));
StringformatTimeDigital(int time)
format Time Digital
int mins = time / 60;
int secondsInteger = time % 60;
String seconds = String.valueOf(secondsInteger);
if (seconds.length() == 1) {
    seconds = "0" + seconds;
return mins + ":" + seconds;
StringformatTimeDuringHour(long mss)
format Time During Hour
long days = mss / 3600000L;
return days + "";
StringformatTimeElapsed(long p_millis)
format elapsed time from millisecond to human readable format
p_millis /= (1000 * 60);
return "" + (p_millis / 60) + "h" + (p_millis % 60);
StringformatTimeInfo(long time)
Get size info
String info = "";
long ms = (long) time;
int i = 1000;
int value = (int) ms % i;
info = value + " millisecond(s)";
ms /= i;
if (ms > 0) {
    i = 60;
...
StringformatTimeInMilisec(long time)
format Time In Milisec
if (time / 1000 < 1) {
    return "0 seconds";
long inMinutes = time / 60000;
long hours = inMinutes / 60;
String formatedTime = "";
if (hours > 0) {
    String unit = hours > 1 ? "hours" : "hour";
...
StringformatTimeInNanos(long time)
format Time In Nanos
return formatDecimal(nanosToMillis(time));