Here you can find the source of seconds2time(long seconds)
public static String seconds2time(long seconds)
//package com.java2s; /*/*from w ww .j a v a2 s. c o m*/ * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ public class Main { /** * Converts a value in seconds to: * "d:hh:mm:ss" where d=days, hh=hours, mm=minutes, ss=seconds, or * "h:mm:ss" where h=hours<24, mm=minutes, ss=seconds, or * "m:ss" where m=minutes<60, ss=seconds */ public static String seconds2time(long seconds) { long minutes = seconds / 60; seconds = seconds - minutes * 60; long hours = minutes / 60; minutes = minutes - hours * 60; long days = hours / 24; hours = hours - days * 24; // build the numbers into a string StringBuilder time = new StringBuilder(); if (days != 0) { time.append(Long.toString(days)); time.append(":"); if (hours < 10) time.append("0"); } if (days != 0 || hours != 0) { time.append(Long.toString(hours)); time.append(":"); if (minutes < 10) time.append("0"); } time.append(Long.toString(minutes)); time.append(":"); if (seconds < 10) time.append("0"); time.append(Long.toString(seconds)); return time.toString(); } }