Java Second to Minute secondsToHoursMinutesSeconds(final long secs)

Here you can find the source of secondsToHoursMinutesSeconds(final long secs)

Description

Converts seconds into hours:minutes:seconds.

License

Open Source License

Parameter

Parameter Description
secs The number of seconds.

Return

The formatted string.

Declaration

public static String secondsToHoursMinutesSeconds(final long secs) 

Method Source Code

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

public class Main {
    /**//w  w  w . j  av a2 s.co m
     * Converts seconds into hours:minutes:seconds.
     * 
     * @param secs The number of seconds.
     * @return The formatted string.
     */
    public static String secondsToHoursMinutesSeconds(final long secs) {
        final double minutesRemaining = (secs / 60) % 60;
        final double hoursRemaining = Math.floor(secs / 60 / 60);
        final double secondsRemaining = secs % 60;

        final StringBuilder sb = new StringBuilder();
        if (hoursRemaining > 0.0) {
            sb.append((int) hoursRemaining);
            sb.append(" hrs, ");
        }
        if (minutesRemaining > 0.0) {
            sb.append((int) minutesRemaining);
            sb.append(" mins, ");
        }
        sb.append((int) secondsRemaining);
        sb.append(" secs");
        return sb.toString();
    }
}

Related

  1. secondsToMinutes(int s)
  2. secondsToMinutes(int seconds)
  3. secondsToMinutes(int seconds)
  4. secondsToMinutes(int time)