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(long timeDiff)
Given the time in long milliseconds, returns a String in the format Xhrs, Ymins, Z sec.
StringBuilder buf = new StringBuilder();
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) {
    buf.append(hours);
...
StringformatTime(long timeDiffMillis)
format Time
StringBuilder buf = new StringBuilder();
long hours = timeDiffMillis / (60 * 60 * 1000);
long rem = (timeDiffMillis % (60 * 60 * 1000));
long minutes = rem / (60 * 1000);
rem = rem % (60 * 1000);
long seconds = rem / 1000;
if (hours != 0) {
    buf.append(hours);
...
StringformatTime(long timeInMilli)
Formats a time given in millisecond.
long hourBasis = 60;
StringBuilder formattedTime = new StringBuilder();
long secTmp = timeInMilli / 1000;
long sec = secTmp % hourBasis;
long minTmp = secTmp / hourBasis;
long min = minTmp % hourBasis;
long hour = minTmp / hourBasis;
if (hour > 0) {
...
StringformatTime(long timeInSecond)
format Time
long hour = timeInSecond / (60 * 60);
long minute = (timeInSecond - (hour * 60 * 60)) / 60;
long second = timeInSecond % 60;
StringBuilder builder = new StringBuilder();
if (hour < 10) {
    builder.append("0" + hour);
} else {
    builder.append(hour);
...
StringformatTime(long timeInterval, int maxTerms)
It converts a given time interval into a week/day/hour/second.milliseconds string.
if (maxTerms > 6)
    throw new IllegalArgumentException();
StringBuilder sb = new StringBuilder(64);
long l = timeInterval;
int termCount = 0;
if (l < 0) {
    sb.append('-');
    l = l * -1;
...
StringformatTime(long timeMillis)
format Time
long time = timeMillis / 1000;
String seconds = Integer.toString((int) (time % 60));
String minutes = Integer.toString((int) ((time % 3600) / 60));
for (int i = 0; i < 2; i++) {
    if (seconds.length() < 2) {
        seconds = "0" + seconds;
    if (minutes.length() < 2) {
...
StringformatTime(long value)
Format the given long value as a CQL time literal, using the following time pattern: hh:mm:ss[.fffffffff] .
int nano = (int) (value % 1000000000);
value -= nano;
value /= 1000000000;
int seconds = (int) (value % 60);
value -= seconds;
value /= 60;
int minutes = (int) (value % 60);
value -= minutes;
...
StringFormatTime(String strTime, char TimeSepartor)
Format Time
String strOutTime;
if (strTime.length() != 6)
    return strTime;
strTime = strTime.substring(0, 2) + TimeSepartor + strTime.substring(2, 4) + TimeSepartor
        + strTime.substring(4);
strOutTime = strTime;
return strOutTime;
StringformatTime(String time)
format Time
Long time_ms = 0L;
try {
    time_ms = Long.parseLong(time);
} catch (NumberFormatException nfe) {
    return ""; 
if (time_ms < 1000) {
    return time_ms + MILLISECOND;
...
StringformatTime(String time)
format Time
String hh = time.substring(0, 2);
String mm = time.substring(2);
return hh + ":" + mm;