Here you can find the source of timeFromSeconds(int timeInSec)
Parameter | Description |
---|---|
timeInSec | time in seconds |
public static String timeFromSeconds(int timeInSec)
//package com.java2s; /*//w ww . j a v a2 s. c o m * Generated on Feb 2, 2009. * * Copyright (C) 2009 Kaiyi Li * * 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 { /** * Given the total number of seconds ,format the time into MM:SS where MM * represents the number of minutes, SS represents the number of seconds. * * @param timeInSec * time in seconds * @return a string representation of time, in MM:SS format. */ public static String timeFromSeconds(int timeInSec) { int min = timeInSec / 60; int sec = timeInSec % 60; StringBuffer time = new StringBuffer(); if (min < 10) { time.append("0"); } time.append(min); time.append(":"); if (sec < 10) { time.append("0"); } time.append(sec); return time.toString(); } }