Java Second timeFromSeconds(int timeInSec)

Here you can find the source of timeFromSeconds(int timeInSec)

Description

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.

License

Open Source License

Parameter

Parameter Description
timeInSec time in seconds

Return

a string representation of time, in MM:SS format.

Declaration

public static String timeFromSeconds(int timeInSec) 

Method Source Code

//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();
    }
}

Related

  1. ticksToSeconds(long ticks)
  2. ticksWithSecondsSetTo(long ticks, int seconds)
  3. timecents2seconds(int timecents)
  4. timeDecimalSeconds(String time)
  5. timeElapsedSecond(long prevTime, long curTime, long periodSecond)
  6. timeFromSeconds(long ms)
  7. timeSpanInSeconds(long time1, long time2)
  8. timeStampSeconds()
  9. timeStringToSeconds(String input)