Java long seconds value convert to time as "00:00:00"

Description

Java long seconds value convert to time as "00:00:00"

public class Main {
  public static void main(String[] argv) {
    long time = 12342;
    System.out.println(convertTime(time));
  }/*from w  w  w . j a  v a 2  s .c  om*/

  public static final String TIME_FORMAT = "00:00:00";

  public static String convertTime(long timelong) {
    if (timelong == 0) {
      return TIME_FORMAT;
    }
    if (timelong > 0) {
      long h = 0, hh = 0;
      long m = 0, mm = 0;
      long s = 0;
      h = timelong / 3600;
      hh = timelong % 3600;
      m = hh / 60;
      mm = hh % 60;
      s = mm;
      String hStr, mStr, sStr = "";
      if (h < 10) {
        hStr = "0" + h;
      } else {
        hStr = "" + h;
      }
      if (m < 10) {
        mStr = "0" + m;
      } else {
        mStr = "" + m;
      }
      if (s < 10) {
        sStr = "0" + s;
      } else {
        sStr = "" + s;
      }
      return hStr + ":" + mStr + ":" + sStr;
    }
    return TIME_FORMAT;
  }
}



PreviousNext

Related