Here you can find the source of secondsToTimeString(int numSeconds)
Parameter | Description |
---|---|
numSeconds | a parameter |
public static CharSequence secondsToTimeString(int numSeconds)
//package com.java2s; /*//from w ww . jav a 2s .c o m * Copyright (C) 2016 Christian DeTamble * * This file is part of Jewel Thief. * * Jewel Thief 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. * * Jewel Thief 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 Jewel Thief. If not, see <http://www.gnu.org/licenses/>. */ public class Main { /** * Converts an integer into the format "(mm:ss)". * * @param numSeconds * @return */ public static CharSequence secondsToTimeString(int numSeconds) { int hours = numSeconds / 3600; int minutes = (numSeconds - (hours * 3600)) / 60; int seconds = Math.max(0, numSeconds - (hours * 3600) - (minutes * 60)); return (hours > 0 ? String.format("%2s", hours).replace(' ', '0') + ":" : "") + String.format("%2s", minutes).replace(' ', '0') + ":" + String.format("%2s", seconds).replace(' ', '0'); } }