Java Millisecond Format getReadableMillisTime(long millis)

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

Description

get Readable Millis Time

License

Open Source License

Declaration

public static String getReadableMillisTime(long millis) 

Method Source Code

//package com.java2s;
/*/*from  w  w w  .  j  ava2 s  .  com*/
 * Copyright (c) 2014. NoxPVP.com
 *
 * All rights are reserved.
 *
 * You are not permitted to
 *    Modify
 *    Redistribute nor distribute
 *    Sublicense
 *
 * You are required to keep this license header intact
 *
 * You are allowed to use this for non commercial purpose only. This does not allow any ad.fly type links.
 *
 * When using this you are required to
 *    Display a visible link to noxpvp.com
 *    For crediting purpose.
 *
 * For more information please refer to the license.md file in the root directory of repo.
 *
 * To use this software with any different license terms you must get prior explicit written permission from the copyright holders.
 */

public class Main {
    public static String getReadableMillisTime(long millis) {
        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;

        int days = (int) (millis % Integer.MAX_VALUE);

        StringBuilder sb = new StringBuilder();
        if (days != 0)
            sb.append(days).append("D ");
        if (hours != 0)
            sb.append(hours).append("H ");
        if (minutes != 0)
            sb.append(minutes).append("M ");
        if (seconds != 0)
            sb.append(seconds).append("S ");
        if (ms != 0)
            sb.append(ms).append("MS ");

        return sb.toString();
    }
}

Related

  1. getFormatedDateTime(long millis)
  2. getFormattedAPILastAccessDate(long lastAccessTimeMillis)
  3. getMillisAsFormattedSeconds(long millis)
  4. getMvoDateFormatForMilliSecond()
  5. getReadableMillis(long startMillis, long endMillis)
  6. getTime(long timeInMillis, SimpleDateFormat dateFormat)
  7. getTimeInMillis(String dateString, String format)
  8. microseconds2milliseconds(double us)
  9. millis2hms(final long t)