Java Second Convert convertSecondsToTimecode(float totalSeconds)

Here you can find the source of convertSecondsToTimecode(float totalSeconds)

Description

Convert the given number of seconds into a timecode string of the form "HH:mm:ss.SSS"

License

Open Source License

Parameter

Parameter Description
totalSeconds a parameter

Return

the timecode string

Declaration

public static String convertSecondsToTimecode(float totalSeconds) 

Method Source Code

//package com.java2s;
/*//w w  w.ja va 2s.c om
 * Copyright (C) 2005-2014 Alfresco Software Limited.
 *
 * This file is part of Gytheio
 *
 * Gytheio is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Gytheio 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 Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with Gytheio. If not, see <http://www.gnu.org/licenses/>.
 */

public class Main {
    /**
     * Convert the given number of seconds into a timecode string of the form
     * "HH:mm:ss.SSS"
     * 
     * @param totalSeconds
     * @return the timecode string
     */
    public static String convertSecondsToTimecode(float totalSeconds) {
        return convertSecondsToTimecode(totalSeconds, 3);
    }

    /**
     * Convert the given number of seconds into a timecode string of the form
     * "HH:mm:ss.SSS" where the given decimalScale indicates the number of
     * digits to retain after the decimal point
     * 
     * 
     * @param totalSeconds
     * @param decimalScale
     * @return the timecode string
     */
    public static String convertSecondsToTimecode(float totalSeconds, int decimalScale) {
        int hours = new Float((totalSeconds / 3600) % 24).intValue();
        String hoursDisplay = String.format("%02d", hours);

        int minutes = new Float((totalSeconds / 60) % 60).intValue();
        String minutesDisplay = String.format("%02d", minutes);

        float seconds = (totalSeconds % 60);

        String secondsDisplay = String.format("%0" + (decimalScale + 3) + "." + decimalScale + "f", seconds);

        return hoursDisplay + ":" + minutesDisplay + ":" + secondsDisplay;
    }
}

Related

  1. convertSecondsToMiliseconds(int secondsToConvert)
  2. convertSecondsToMillies(final long seconds)
  3. convertSecondsToString(double seconds)
  4. convertSecondsToTime(int seconds)
  5. convertSecondsToTime(int totalSecs)
  6. convertSecondsToTimeUnits(int seconds)
  7. convertTimecodeToSeconds(String timecode)
  8. convertTimemilisecondsToHours(long time)
  9. convertTimeSecondsToHMS(long longSecs)