Java Second Convert secondsToTimeString(int numSeconds)

Here you can find the source of secondsToTimeString(int numSeconds)

Description

Converts an integer into the format "(mm:ss)".

License

Open Source License

Parameter

Parameter Description
numSeconds a parameter

Declaration

public static CharSequence secondsToTimeString(int numSeconds) 

Method Source Code

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

Related

  1. secondsToTime(int seconds)
  2. secondsToTime(long timeseconds)
  3. secondsToTimeClock(int totalSeconds)
  4. secondsToTimecode(long seconds)
  5. secondsToTimeDisplay(Object value)
  6. secondsToTimeString(long in_seconds)
  7. secondsToTimeString(long seconds)
  8. secondsToYWDHMS(long seconds)
  9. SecondToMin(double asec)