Java Millisecond Current Get getMillisDurationString(long millis)

Here you can find the source of getMillisDurationString(long millis)

Description

get Millis Duration String

License

Apache License

Declaration

public static String getMillisDurationString(long millis) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.text.DecimalFormat;
import java.text.NumberFormat;

public class Main {
    private static final NumberFormat MEM_FMT = new DecimalFormat("##,###.##");

    public static String getMillisDurationString(long millis) {
        long secs = millis / 1000;
        long mins = secs / 60;
        long remainingSecs = secs % 60;
        if (mins > 0) {
            return String.format("%d mins %d secs", mins, remainingSecs);
        } else {//from  w w w. ja v  a  2  s  .c  om
            return String.format("%.3f secs", millis / 1000.0);
        }
    }

    private static String format(long bytes) {
        double val = bytes;
        int mag = 0;
        while (val > 1024) {
            val = val / 1024;
            mag++;
        }

        String formatted = MEM_FMT.format(val);
        switch (mag) {
        case 0:
            return formatted + " bytes";
        case 1:
            return formatted + " kb";
        case 2:
            return formatted + " Mb";
        case 3:
            return formatted + " Gb";
        default:
            return "WTF?";
        }
    }
}

Related

  1. getCurrentMillisecond()
  2. getCurrentMillisecondString()
  3. getCurrentMillisecondZeroFillString()
  4. getCurrentTimeMillisStr()
  5. getMillins(String yyyyMMddHHmmss)
  6. getMillisec_old(String isoDate)
  7. getMillisecondStamp(Date date)
  8. getMilliSecondToTomorrow(Date date)
  9. getMillisFromISO8601(Object iso8601)