Java Second Format secondsToTime(double seconds)

Here you can find the source of secondsToTime(double seconds)

Description

seconds To Time

License

Open Source License

Declaration

public static String secondsToTime(double seconds) 

Method Source Code

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

import java.text.DecimalFormat;

public class Main {
    public static String secondsToTime(double seconds) {
        String result;/*from   w  w w.  j a va 2  s  .  c  o m*/

        int minutes = (int) (seconds / 60);
        seconds = seconds % 60;
        result = new DecimalFormat("#.###").format(seconds) + "s";
        if (minutes == 0) {
            return result;
        }

        int hours = minutes / 60;
        minutes = minutes % 60;
        result = minutes + "m " + result;
        if (hours == 0) {
            return result;
        }

        int days = hours / 24;
        hours = hours % 24;
        result = hours + "h " + result;
        if (days == 0) {
            return result;
        }

        return days + "d " + result;
    }
}

Related

  1. secondsToDHMSString(double seconds)
  2. secondstoHM(long sec)
  3. secondsToHumanDate(long seconds)
  4. secondsToString(long seconds)
  5. secondsToStringFormat(long seconds)
  6. secondsToTimeString(long numSeconds)
  7. toSecondString(long time)