Java Time Format formatTime(double totalTime)

Here you can find the source of formatTime(double totalTime)

Description

format Time

License

Apache License

Declaration

public static String formatTime(double totalTime) 

Method Source Code

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

public class Main {
    public static String formatTime(double totalTime) {
        if (totalTime > 60) {
            double mins = totalTime / 60;
            int secs = (int) totalTime % 60;

            if (mins > 60) {
                int hors = (int) (mins / 60);
                mins = mins % 60;/*from   w  w  w. ja  v a  2  s  . c om*/
                int m = (int) mins;

                if (secs == 0) {
                    if (m == 0) {
                        return Integer.toString(hors) + "h";
                    } else {
                        return Integer.toString(hors) + "h" + Integer.toString(m) + "m";
                    }
                } else {
                    if (m == 0) {
                        return Integer.toString(hors) + "h" + Integer.toString(secs) + "s";
                    } else {
                        return Integer.toString(hors) + "h" + Integer.toString(m) + "m" + Integer.toString(secs)
                                + "s";
                    }
                }
            } else {
                int m = (int) mins;
                if (secs == 0) {
                    return Integer.toString(m) + "m";
                } else {
                    return Integer.toString(m) + "m" + Integer.toString(secs) + "s";
                }
            }
        } else {
            int t = (int) totalTime;
            return Integer.toString(t) + "s";
        }
    }
}

Related

  1. formatString(String agentId, long agentStartTime, long transactionSequence)
  2. formattedStats(String pExecTime, int pTxns)
  3. formattedUnixTime()
  4. formatTime(byte[] btValue, int iOffset, int iLength)
  5. formatTime(double time)
  6. formatTime(final int timeSec)
  7. formatTime(final long time)
  8. formatTime(final long time)
  9. formatTime(final long timeMS)