Java Second Convert secondsToTimeDisplay(Object value)

Here you can find the source of secondsToTimeDisplay(Object value)

Description

Converts a long into a string that represents the music time.

License

Open Source License

Parameter

Parameter Description
value a parameter

Declaration

public static String secondsToTimeDisplay(Object value) 

Method Source Code

//package com.java2s;
/*//ww w.  j a  v  a 2  s .  c om
* The GPLv3 licence :
* -----------------
* Copyright (c) 2009 Ricardo Dias
*
* This file is part of MuVis.
*
* MuVis 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.
*
* MuVis 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 MuVis.  If not, see <http://www.gnu.org/licenses/>.
*/

public class Main {
    /**
     * Converts a long into a string that represents the music time.
     * Format: (hh:mm:ss)
     * @param value
     * @return
     */
    public static String secondsToTimeDisplay(Object value) {

        String timeDisplay = "";

        if (value instanceof Long) {
            long valueLong = (Long) value;
            long hours = valueLong / 3600;
            long minutes = (valueLong - (hours * 3600)) / 60;
            long seconds = (valueLong - (hours * 3600) - (minutes * 60));

            if (hours != 0) {
                if (hours < 10) {
                    timeDisplay += "0";
                }
                timeDisplay += hours + ":";
            }
            if (minutes < 10) {
                timeDisplay += "0";
            }
            timeDisplay += minutes + ":";

            if (seconds < 10) {
                timeDisplay += "0" + seconds;
            } else {
                timeDisplay += seconds;
            }
        }

        return timeDisplay;

    }
}

Related

  1. secondsToTime(int seconds)
  2. secondsToTime(int seconds)
  3. secondsToTime(long timeseconds)
  4. secondsToTimeClock(int totalSeconds)
  5. secondsToTimecode(long seconds)
  6. secondsToTimeString(int numSeconds)
  7. secondsToTimeString(long in_seconds)
  8. secondsToTimeString(long seconds)
  9. secondsToYWDHMS(long seconds)