Java Utililty Methods Millisecond Convert

List of utility methods to do Millisecond Convert

Description

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

Method

StringgetDuration(final long millis)
get Duration
DecimalFormat df20 = new DecimalFormat("00");
DecimalFormat df30 = new DecimalFormat("000");
Calendar c = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
c.setTimeInMillis(millis);
return new StringBuffer(12).append(df20.format(c.get(Calendar.HOUR_OF_DAY))).append(":")
        .append(df20.format(c.get(Calendar.MINUTE))).append(":").append(df20.format(c.get(Calendar.SECOND)))
        .append(".").append(df30.format(c.get(Calendar.MILLISECOND))).toString();
StringgetDurationBreakdown(long durationInMillis)
Convert a millisecond duration to a string format
if (durationInMillis < 0) {
    throw new IllegalArgumentException("Duration must be greater than zero!");
return (new SimpleDateFormat("mm:ss:SSS")).format(new Date(durationInMillis));
longgetDurationMillisecond(Date date1, Date date2)
get Duration Millisecond
return date2.getTime() - date1.getTime();
StringgetHumanDisplayForTimediff(Long diffMillis)
get Human Display For Timediff
if (diffMillis == null) {
    return "";
long day = diffMillis / (24 * 60 * 60 * 1000);
long hour = (diffMillis / (60 * 60 * 1000) - day * 24);
long min = ((diffMillis / (60 * 1000)) - day * 24 * 60 - hour * 60);
long se = (diffMillis / 1000 - day * 24 * 60 * 60 - hour * 60 * 60 - min * 60);
StringBuilder sb = new StringBuilder();
...
StringgetNice(long timeMillisecGMT)
Return nice given MMILIS since EPOCH
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
format.setTimeZone(TimeZone.getTimeZone("GMT"));
return format.format(new Date(timeMillisecGMT));
StringgetStringFromMillis(long timestamp)
get String From Millis
DateFormat df = DateFormat.getDateTimeInstance();
return df.format(new Date(timestamp));
StringgetTime(long millis)
get Time
return formattor.format(new Date(millis));
StringgetTime(long time, boolean withMilliseconds)
get Time
SimpleDateFormat dateFormat = getDateFormat(withMilliseconds);
return dateFormat.format(new Date(time));
StringgetTimeByMillis(long now)
get Time By Millis
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(now);
return formatter.format(calendar.getTimeInMillis());
StringgetTimeFromMillisAsNICSDate(long timeInMillis)
get Time From Millis As NICS Date
SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
fmt.setTimeZone(TimeZone.getTimeZone("UTC"));
return fmt.format(getDateFromMillis(timeInMillis));