One - One Code All

Blog Content

java将总秒数转换为时分秒

Java   2009-02-28 14:02:09

将总秒数转换为时分秒。

    /**
     * 将总秒数转换为时分秒
     *
     * @param strTime 秒数
     * @return 时分秒
     */
    public String secToTime(String strTime) {
        int seconds = Integer.parseInt(strTime);
        int temp = 0;
        StringBuffer sb = new StringBuffer();
		// / 除法,取商的整数; % 取模,取余数
        temp = seconds / 3600;
        sb.append((temp < 10) ? "0" + temp + ":" : "" + temp + ":");
        temp = seconds % 3600 / 60;
        sb.append((temp < 10) ? "0" + temp + ":" : "" + temp + ":");
        temp = seconds % 3600 % 60;
        sb.append(( temp < 10) ? "0" + temp : "" + temp);
        return sb.toString();
    }



上一篇:python长字符串换行的三种方式
下一篇:般若波罗蜜多心经

The minute you think of giving up, think of the reason why you held on so long.