Java - Write code to convert long value to Time

Requirements

Write code to convert long value to Time

Demo

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

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

  public static String convertTime(Long time) {
    long timelong = time.longValue();
    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;
  }
}

Related Exercise