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

StringgetFormatedDateTime(long millis)
get Formated Date Time
return sdf2.format(millis);
StringgetFormattedAPILastAccessDate(long lastAccessTimeMillis)
Get the formatted date string of API Last Access Time
DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy  HH:mm");
return dateFormat.format(lastAccessTimeMillis);
StringgetMillisAsFormattedSeconds(long millis)
Convert a number of milliseconds into seconds, we format to 2 decimal places, i.e.
long secs = millis / 1000;
long tenths = (millis - (secs * 1000)) / 100;
long hundredths = (millis - (secs * 1000) - (tenths * 100)) / 10;
return secs + "." + tenths + hundredths;
SimpleDateFormatgetMvoDateFormatForMilliSecond()
get Mvo Date Format For Milli Second
return new SimpleDateFormat("yyyy.MM.dd-HH:mm:ss.SSS");
StringgetReadableMillis(long startMillis, long endMillis)
get Readable Millis
StringBuilder sb = new StringBuilder();
double elapsedSeconds = (endMillis - startMillis) / 1000.0;
int elapsedSecs = ((int) elapsedSeconds) % 60;
int elapsedMinutes = (int) (elapsedSeconds / 60.0);
int elapsedMins = elapsedMinutes % 60;
int elapsedHrs = elapsedMinutes / 60;
int elapsedHours = elapsedHrs % 24;
int elapsedDays = elapsedHrs / 24;
...
StringgetReadableMillisTime(long millis)
get Readable Millis Time
int ms = (int) (millis % 1000);
millis /= 1000;
int seconds = (int) (millis % 60);
millis /= 60;
int minutes = (int) (millis % 60);
millis /= 60;
int hours = (int) (millis % 24);
millis /= 24;
...
StringgetTime(long timeInMillis, SimpleDateFormat dateFormat)
long time to string
return dateFormat.format(new Date(timeInMillis));
longgetTimeInMillis(String dateString, String format)
get Time In Millis
long ts = 0L;
try {
    SimpleDateFormat sdf = new SimpleDateFormat(format);
    Date date = sdf.parse(dateString);
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);
    calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
    calendar.set(Calendar.HOUR_OF_DAY, 0);
...
doublemicroseconds2milliseconds(double us)
microsecondsmilliseconds
return 0.001 * us;
Stringmillis2hms(final long t)
Convert milliseconds to hours, minutes seconds.
if (t < 0) {
    return "INVALID MILLISECONDS: " + t;
if (t < 1000) {
    return t + "ms";
final long s = (t / 1000) % 60;
final long m = ((t / 1000) / 60) % 60;
...