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

Stringformat_duration(long millis)
formaduration
String DATE_FORMAT_NOW = "HH:mm:ss";
SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW);
sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
return sdf.format(new Date(millis));
StringformatCcsdsUtcMillisFormat(Date time)
format Ccsds Utc Millis Format
if (time == null) {
    return "";
return CCSDS_UTC_MILLIS_FORMAT.format(time);
StringformatDataTimeStamp(final long timeInMillis)
Formats a date into a standard timestamp format: yy-MM-dd HH:mm:ss.SSS
final String timeFormat = "yy-MM-dd HH:mm:ss.SSS";
return formatDateTimeStamp(timeInMillis, timeFormat);
StringformatElapsedMillis(long time)
Formats a time in milleseconds (typically elapsed time) into a string with format "[d'd'] hh:mm:ss.mmmm".
int timeInt = (int) time;
int mils = timeInt % 1000;
timeInt /= 1000;
int secs = timeInt % 60;
timeInt /= 60;
int mins = timeInt % 60;
timeInt /= 60;
int hours = timeInt % 24;
...
StringformatElapsedTime(long millis)
Format an elapsed time into a plurialization correct string.
long seconds = millis / 1000;
long minutes = seconds / 60;
Object[] args = { new Long(minutes), new Long(seconds % 60) };
return MINUTE_SECONDS.format(args);
StringformateTime(long milliseconds)
formate Time
SimpleDateFormat formatter = new SimpleDateFormat(TIMEFORMAT_WITHOUT_SECONDS);
Date date = new Date(milliseconds);
formatter.setTimeZone(TimeZone.getTimeZone("GMT+8"));
return formatter.format(date);
StringformatMillis(int millis, int digits)
Used to by formatCalendar* to format millisecond field.
if (digits == 0)
    return "";
StringBuffer sb = new StringBuffer(16);
sb.append('.');
sb.append(millis);
while (sb.length() > digits && sb.charAt(sb.length() - 1) == '0') {
    sb.deleteCharAt(sb.length() - 1); 
while (sb.length() < digits + 1) {
    sb.append('0'); 
return sb.toString();
StringformatMillis(long duration)
format Millis
duration = Math.abs(duration);
StringBuilder sb = new StringBuilder();
int secs = (int) (duration / 1000) % 60;
int mins = (int) ((duration / (1000 * 60)) % 60);
int hrs = (int) ((duration / (1000 * 60 * 60)) % 24);
int days = (int) ((duration / (1000 * 60 * 60 * 24)) % 7);
addUnitString(sb, days, "day");
addUnitString(sb, hrs, "hour");
...
StringformatMillis(long millis)
format Millis
millis /= 1000;
long h = millis / 3600;
millis -= 3600 * h;
long m = millis / 60;
millis -= 60 * m;
return "" + (h < 10 ? "0" : "") + h + ":" + (m < 10 ? "0" : "") + m + ":" + (millis < 10 ? "0" : "")
        + millis;
StringformatMillis(long millis)
format Millis
if (millis == 0L) {
    return "0";
StringBuilder millisString = new StringBuilder();
long leftover = millis;
if (leftover >= 86400000L) {
    millisString.append(leftover / 86400000L).append("d ");
    leftover %= 86400000L;
...