Method to convert seconds to hours, minutes, seconds. - Java java.util

Java examples for java.util:Minute

Description

Method to convert seconds to hours, minutes, seconds.

Demo Code


//package com.java2s;

import java.math.BigDecimal;

public class Main {
    /**//w ww.  j  av a 2s.c o m
     * Method to convert seconds to hours, minutes, seconds.
     * 
     * @param biggy
     *            Receives the seconds.
     * @return The value.
     */
    public static String convertSecondsToTime(BigDecimal biggy) {
        long longVal = biggy.longValue();
        int hours = (int) longVal / 3600;
        int remainder = (int) longVal - hours * 3600;
        int mins = remainder / 60;
        remainder = remainder - mins * 60;
        int secs = remainder;
        return hours + " hours, " + mins + " mins, " + secs + " secs.";
    }
}

Related Tutorials