Java Time Format formatTime(long time)

Here you can find the source of formatTime(long time)

Description

format Time

License

Open Source License

Declaration

public static String formatTime(long time) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static String formatTime(long time) {
        StringBuilder ret = new StringBuilder();
        int days = (int) Math.floor(time / (1000 * 3600 * 24));
        int hours = (int) Math.floor((time % (1000 * 3600 * 24)) / (1000 * 3600));
        int minutes = (int) Math.floor((time % (1000 * 3600 * 24)) % (1000 * 3600) / (1000 * 60));
        int seconds = (int) Math.floor(time % (1000 * 3600 * 24) % (1000 * 3600) % (1000 * 60) / 1000);

        if (days != 0)
            ret.append(days + "d");
        if (hours != 0 || days != 0)
            ret.append(hours + "h");
        if (minutes != 0 || hours != 0 || days != 0)
            ret.append(minutes + "m");
        ret.append(seconds + "s");

        return ret.toString();
    }/*  w w  w. j a  v a 2s  . c  o  m*/
}

Related

  1. formatTime(long seconds)
  2. formatTime(long seconds)
  3. formatTime(long time)
  4. formatTime(long time)
  5. formatTime(long time)
  6. formatTime(long time)
  7. formatTime(long time)
  8. formatTime(long time)
  9. formatTime(long time)