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

StringcalFormatTime(final Calendar cal)
Formats a Calendar to the application wide format for time
SimpleDateFormat sdf = new SimpleDateFormat(TIME_FORMAT);
return sdf.format(cal.getTime());
booleancompareTime(String time1, String time2, String dateFormat)
compare Time
SimpleDateFormat t1 = new SimpleDateFormat(dateFormat);
SimpleDateFormat t2 = new SimpleDateFormat(dateFormat);
try {
    Date d1 = t1.parse(time1);
    Date d2 = t2.parse(time2);
    return d1.before(d2);
} catch (Exception e) {
    e.printStackTrace();
...
DateFormatcreateTimeFormatter(String languageCode)
create Time Formatter
DateFormat formatter = null;
if ((languageCode != null) && !("".equalsIgnoreCase(languageCode.trim()))) {
    languageCode = languageCode.trim();
    Locale locale = new Locale(languageCode.substring(2, 4).toLowerCase(), languageCode.substring(0, 2));
    formatter = DateFormat.getTimeInstance(DateFormat.SHORT, locale);
} else {
    formatter = DateFormat.getTimeInstance(DateFormat.SHORT);
return formatter;
Stringformat(long time)
format
if (-60000 < time && time < 60000) {
    return formatSeconds(time);
if (time == Long.MAX_VALUE) {
    return "DNF";
String sign = "";
if (time < 0) {
...
Stringformat(long time)
format
return String.valueOf(time) + " in game ticks.";
Stringformat(long time, String timerPrecisionId, boolean round)
format
if (-60000 < time && time < 60000) {
    return formatSeconds(time, timerPrecisionId, round);
String result = "";
if (time == Long.MAX_VALUE) {
    return "DNF";
String sign = "";
...
Stringformat(String format, long time)
format
long seconds = (time / 1000) % 60;
long minutes = (time / (1000 * 60)) % 60;
long hours = (time / (1000 * 60 * 60)) % 24;
return String.format(format, hours, minutes, seconds);
StringformatBenchResult(final String benchName, final int iterationCount, final int benchNumber, final double benchTime)
format Bench Result
return benchName + " | repeat: " + benchNumber + " | iterationCount: " + iterationCount + " | time: "
        + benchTime;
StringformatCooldown(long time)
format Cooldown
long hours = time / 3600;
long minutes = (time % 3600) / 60;
long seconds = time % 60;
String currentCooldown = "";
if (hours > 0) {
    currentCooldown = String.format("%dh %dm %ds", hours, minutes, seconds);
} else if (minutes > 0) {
    currentCooldown = String.format("%dm %ds", minutes, seconds);
...
StringformatDateTime(String DateTimeStr)
format Date Time
if (DateTimeStr != null) {
    return "{ts '" + DateTimeStr + "'}";
} else {
    return null;