Here you can find the source of formatSeconds(int seconds)
Parameter | Description |
---|---|
seconds | seconds to be formatted |
public static String formatSeconds(int seconds)
//package com.java2s; //License from project: Apache License public class Main { /**/* w ww .ja va 2 s. c om*/ * Formats the specified amount of seconds to a short format. * @param seconds seconds to be formatted * @return the formatted seconds in short format */ public static String formatSeconds(int seconds) { int hour = 0, min = 0; if (seconds >= 3600) { hour = seconds / 3600; seconds = seconds % 3600; } if (seconds >= 60) { min = seconds / 60; seconds = seconds % 60; } return hour > 0 ? hour + (min < 10 ? ":0" : ":") + min + (seconds < 10 ? ":0" : ":") + seconds : min + (seconds < 10 ? ":0" : ":") + seconds; } }