Java Second Convert secondsToTimecode(long seconds)

Here you can find the source of secondsToTimecode(long seconds)

Description

seconds To Timecode

License

Open Source License

Declaration

public static String secondsToTimecode(long seconds) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static String secondsToTimecode(long seconds) {
        long hours = 0;
        long mins = 0;
        long secs = 0;

        hours = seconds / 3600L;/*www .j a va2 s  . com*/
        seconds -= (hours * 3600);

        mins = seconds / 60L;
        secs = seconds - (mins * 60L);

        String result = String.format(":%02d", Long.valueOf(secs));
        if ((hours > 0L) || (mins > 0L)) {
            String fmt = (hours > 0L) ? "%02d" : "%d";
            result = String.format(fmt + "%s", Long.valueOf(mins), result);
        }
        if (hours > 0L) {
            result = String.format("%d:%s", Long.valueOf(hours), result);
        }
        return result;
    }
}

Related

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