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

StringformatDateTime(String s)
format Date Time
if (!s.contains(" "))
    return s;
return s.trim().replace(" ", "T") + "Z";
StringformatDateTime(String value)
format Date Time
if (value == null) {
    return null;
if (value.length() != DATE_TIME_STRING_LENGTH) {
    return addGMToffset(value);
} else {
    return value;
StringformatDateTimeString(final String dateTimeString, final boolean wrapForCodeUsage)
format Date Time String
if (wrapForCodeUsage) {
    return "date and time( \"" + dateTimeString + "\" )";
} else {
    return dateTimeString;
StringformatDelay(long startTime, long endTime)
format Delay
final long delay = ((endTime - startTime) / 1000);
final long sec = (delay / 1000000);
final long usec = (delay % 1000000);
return String.format("%d.%06d", sec, usec);
StringformatElapsedTime(int seconds)
format Elapsed Time
String sPlural = (seconds == 1 ? "" : "s");
if (seconds < 60)
    return Integer.toString(seconds) + " second" + sPlural;
int s = (seconds % 60);
sPlural = (seconds == 1 ? "" : "s");
int m = seconds / 60;
String mPlural = (m == 1 ? "" : "s");
return Integer.toString(m) + " minute" + mPlural
...
StringformatElapsedTime(long elapsedTime)
format Elapsed Time
return String.format("%d:%02d:%02d", elapsedTime / 3600, (elapsedTime % 3600) / 60, (elapsedTime % 60)); 
StringformatElapsedTime(long time)
format Elapsed Time
long ms = time % 1000;
time = time / 1000;
long sec = time % 60;
time = time / 60;
long min = time % 60;
time = time / 60;
long hour = time % 24;
time = time / 24;
...
StringformatEndRowKeyString(String id, String timestampEnd)
HBase takes in a string to end the scan at.
String endRowKeyString = null;
if (timestampEnd != null && timestampEnd != "") {
    timestampEnd = formatTimestampEnd(timestampEnd);
} else {
    id = formatId(id);
endRowKeyString = buildRowKeyFilterString(id, timestampEnd);
return endRowKeyString;
...
StringformatExecutionTime(long executionTime)
Format execution time for log.
long min = executionTime / (1000 * 60L);
executionTime = executionTime - min * 1000 * 60L;
long sec = executionTime / 1000L;
long millis = executionTime - sec * 1000L;
StringBuilder sb = new StringBuilder();
sb.append(min + " min. ");
sb.append(sec + " sec. ");
sb.append(millis + " millis");
...
StringformatExecutionTime(long ms)
format Execution Time
if (ms < 60000) {
    return String.valueOf(ms) + "ms";
long sec = ms / 1000;
long min = sec / 60;
sec -= min * 60;
return String.valueOf(min) + " min " + String.valueOf(sec) + " sec";