Java Second Convert secondsToTime(int seconds)

Here you can find the source of secondsToTime(int seconds)

Description

Parses the seconds and returns time in HOUR:MIN:SEC format

License

Open Source License

Parameter

Parameter Description
seconds Seconds to parse

Return

Time in user-friendly format

Declaration

public static String secondsToTime(int seconds) 

Method Source Code

//package com.java2s;
/*//from   w w  w.  j a  va 2 s  . c o  m
 * Util.java
 * 
 * PrisonMine
 * Copyright (C) 2013 bitWolfy <http://www.wolvencraft.com> and contributors
 *
 * 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 {
    /**
     * Parses the seconds and returns time in HOUR:MIN:SEC format
     * @param seconds Seconds to parse
     * @return Time in user-friendly format
     */
    public static String secondsToTime(int seconds) {
        int hour = (int) Math.floor(seconds / 3600);
        int min = (int) Math.floor((seconds - (hour * 3600)) / 60);
        int sec = seconds - (hour * 3600) - (min * 60);
        String resetTime = min + ":";
        if (min < 10)
            resetTime = "0" + resetTime;
        resetTime = hour + ":" + resetTime;
        if (sec < 10)
            resetTime = resetTime + "0";
        resetTime = resetTime + sec;
        return resetTime;
    }
}

Related

  1. secondsToTicks(double seconds)
  2. secondsToTicks(double x)
  3. secondsToTicks(float seconds)
  4. secondsToTicks(int seconds)
  5. secondsToTime(double seconds)
  6. secondsToTime(int seconds)
  7. secondsToTime(long timeseconds)
  8. secondsToTimeClock(int totalSeconds)
  9. secondsToTimecode(long seconds)