Android Long to Date Convert getReadableTimeUsage(long timeUsageMs)

Here you can find the source of getReadableTimeUsage(long timeUsageMs)

Description

Format the time usage to string like "1d17h37m3s728ms"

License

Apache License

Parameter

Parameter Description
timeUsageMs a parameter

Declaration

public static String getReadableTimeUsage(long timeUsageMs) 

Method Source Code

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

public class Main {
    /**/*  ww  w.j a v  a2  s. c o m*/
     * Format the time usage to string like "1d17h37m3s728ms"
     * @param timeUsageMs
     * @return
     */
    public static String getReadableTimeUsage(long timeUsageMs) {
        long millisecondsLeft = timeUsageMs % 1000;
        if (timeUsageMs == millisecondsLeft) {
            return millisecondsLeft + "ms";
        }

        long seconds = timeUsageMs / 1000;
        long secondsLeft = seconds % 60;
        if (secondsLeft == seconds) {
            return secondsLeft + "s" + millisecondsLeft + "ms";
        }

        long minutes = seconds / 60;
        long minutesLeft = minutes % 60;
        if (minutesLeft == minutes) {
            return minutesLeft + "m" + secondsLeft + "s" + millisecondsLeft
                    + "ms";
        }

        long hours = minutes / 60;
        long hoursLeft = hours % 24;
        if (hoursLeft == hours) {
            return hoursLeft + "h" + minutesLeft + "m" + secondsLeft + "s"
                    + millisecondsLeft + "ms";
        }

        long days = hours / 24;
        return days + "d" + hoursLeft + "h" + minutesLeft + "m"
                + secondsLeft + "s" + millisecondsLeft + "ms";
    }
}

Related

  1. getMonth(long dateTimeMillis)
  2. getNameForDcim(long time)
  3. getNameForFile(long time)
  4. getNumberOfDaysPassed(long date1, long date2)
  5. getReadableTimeStamp(long timeStamp)
  6. getRelativeDateLabel(long time)
  7. getRelativeTimeFromMilliSeconds(long dateInMillis)
  8. getShortDateString(long date, Locale locale)
  9. getShortDateTimeString(long date, Locale locale)