Java Long Number to Time convertTime(long time)

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

Description

Method description

License

Open Source License

Parameter

Parameter Description
time a parameter

Declaration

public static String convertTime(long time) 

Method Source Code

//package com.java2s;

public class Main {
    /**//from   w ww  .  jav a  2s . c  om
     * Method description
     *
     *
     * @param time
     *
     * @return
     */
    public static String convertTime(long time) {
        String suffix = "ms";

        if (time > 1000) {
            time /= 1000;
            suffix = "s";

            if (time > 60) {
                time /= 60;
                suffix = "m";

                if (time > 60) {
                    time /= 60;
                    suffix = "h";
                }
            }
        }

        return time + suffix;
    }

    /**
     * Method description
     *
     *
     * @param timeString
     *
     * @return
     */
    public static long convertTime(String timeString) {
        char suffix = timeString.charAt(timeString.length() - 1);
        long time = Long.parseLong(timeString.substring(0, timeString.length() - 1));

        switch (suffix) {
        case 'h':
            time *= 60;
        case 'm':
            time *= 60;
        case 's':
            time *= 1000;
        }

        return time;
    }
}

Related

  1. ConvertLongToTimeString(long lastModified)
  2. convertMillisToHHMMSS(long millis)
  3. convertMillsToDateString(long currentTimeMillis)
  4. convertTime(long difference)
  5. convertTime(Long time)
  6. convertTime(long time)
  7. convertTime(long time)
  8. convertTime(long time)
  9. convertTime(long value)