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

StringformatRuntime(long time, boolean fixedlength)
Formats the runtime for output
double h_full = ((double) time) / 3600000;
long h = (long) h_full;
double min_full = ((h_full - h) * 60);
long min = (long) min_full;
double sec_full = ((min_full - min) * 60);
long sec = (long) sec_full;
double msec_full = ((sec_full - sec) * 1000);
long msec = (long) msec_full;
...
StringformatSample(final int aValue, final long aTimestamp)
Formats the given value and timestamp into a single sample string.
final String hexVal = Integer.toHexString(aValue & Integer.MAX_VALUE);
final StringBuilder sb = new StringBuilder();
sb.append("00000000".substring(hexVal.length()));
sb.append(hexVal);
sb.append("@");
sb.append(Long.toString(aTimestamp & Long.MAX_VALUE));
return sb.toString();
StringformatSignificantElapsedTime(final long seconds)
Print only the most significant portion of the time.
final long days = seconds / 86400;
final StringBuffer buffer = new StringBuffer();
if (days > 0) 
    buffer.append(days);
    buffer.append("d ");
    buffer.append(((seconds / 3600) % 24)); 
    buffer.append("h");
...
StringformatStartRowKeyString(String id, String timestampStart)
HBase takes in a string to start the scan at.
timestampStart = formatTimestampStart(timestampStart);
String startRowKeyString = buildRowKeyFilterString(id, timestampStart);
return startRowKeyString;
StringformatStrDateTime(String stringDateTime)
format Str Date Time
stringDateTime = stringDateTime.replaceAll(":", "");
stringDateTime = stringDateTime.replaceAll("-", "");
stringDateTime = stringDateTime.replaceAll(" ", "");
return stringDateTime;
StringformatString(String agentId, long agentStartTime, long transactionSequence)
format String
if (agentId == null) {
    throw new NullPointerException("agentId must not be null");
StringBuilder sb = new StringBuilder(64);
sb.append(agentId);
sb.append(TRANSACTION_ID_DELIMITER);
sb.append(agentStartTime);
sb.append(TRANSACTION_ID_DELIMITER);
...
StringformattedStats(String pExecTime, int pTxns)
formatted Stats
String result = "";
result = Integer.toString(pTxns) + " txns, in " + pExecTime + " secs.";
return result;
StringformattedUnixTime()
formatted Unix Time
return Long.toString(System.currentTimeMillis());
StringformatTime(byte[] btValue, int iOffset, int iLength)
format Time
if ((btValue.length < iOffset + iLength) || (iLength < 3))
    return "";
return getBCDString(btValue[iOffset + 0]) + ":" + getBCDString(btValue[iOffset + 1]) + ":"
        + getBCDString(btValue[iOffset + 2]);
StringformatTime(double time)
format Time
int hours = (int) time / 3600;
int minutes = (int) (time - (hours * 3600)) / 60;
int seconds = (int) time - (hours * 3600) - (minutes * 60);
String hoursString = hours + "";
String minutesString = minutes + "";
String secondsString = seconds + "";
while (minutesString.length() < 2) {
    minutesString = "0" + minutesString;
...