Java Utililty Methods Millisecond Format

List of utility methods to do Millisecond Format

Description

The list of methods to do Millisecond Format are organized into topic(s).

Method

StringcreateDateTimeString(final long ms, final DateFormat timeFormat, final String milliSep)
Creates a string from a date given the appropriate time format and millisecond separator.
final long seconds = ms / MS_IN_SEC;
final long fraction = ms - seconds * MS_IN_SEC;
String millis = Long.toString(fraction);
millis = leftPad(millis, THREE, '0');
final SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
sdf.setTimeZone(UTC_TIME_ZONE);
final Date date = new Date(ms);
final StringBuilder builder = new StringBuilder(128);
...
Stringformat(final long timeInMillis)
Formats milliseconds into a String date representation of:
solely seconds when less than 59999 or minutes and seconds when more.
return (isLessThanMinute(timeInMillis) ? SIMPLE_DATE_SECONDS_FORMAT : SIMPLE_DATE_MINUTE_SECONDS_FORMAT)
        .format(new Date(timeInMillis));
Stringformat(long millis)
format
int mins = 0;
double secs = 0;
if (millis != 0) {
    double time = (double) millis / 1000;
    mins = (int) (time / 60);
    secs = time - mins * 60;
StringBuilder result = new StringBuilder();
...
Stringformat(long millis)
formats the millis in human readable format
String retVal = "";
if (millis < MILLIS) {
    retVal = new SimpleDateFormat(MILLIS_FORMAT).format(new Date(millis));
} else if (millis < SECONDS) {
    retVal = new SimpleDateFormat(SECONDS_FORMAT).format(new Date(millis));
} else if (millis < MINUTES) {
    retVal = new SimpleDateFormat(MINUTES_FORMAT).format(new Date(millis));
} else if (millis < HOURS) {
...
Stringformat(long millis)
Format the millisecond timestamp to a human-readable timestamp.
return def.format(new Date(millis));
Stringformat(long millis)
format
return format(millis, ISO_DATETIME_FORMAT);
Stringformat(long millis, String pattern)

Formats a date/time into a specific pattern.

return format(new Date(millis), pattern, null);
Stringformat(long milliseconds, String format)
format
SimpleDateFormat sdf = new SimpleDateFormat(format);
sdf.setTimeZone(CURRENT_TIME_ZONE);
Date t = new Date();
t.setTime(milliseconds);
return sdf.format(t);
Stringformat(long timeMillis)
format
DateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT_GMT, local);
dateFormat.setTimeZone(timeZone);
return dateFormat.format(new Date(timeMillis));
Stringformat(long timeMillis, String pattern)
format
if (timeMillis > 0L) {
    DateFormat dateFormat = new SimpleDateFormat(pattern);
    return dateFormat.format(new Date(timeMillis));
return "";