Java Second Convert SecondsToString(long seconds)

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

Description

Formats number of seconds to a string consists of number of seconds, minutes, hours or days and the corresponding entity (e.g.

License

BSD License

Parameter

Parameter Description
seconds a parameter

Declaration

public static String SecondsToString(long seconds) 

Method Source Code

//package com.java2s;
/*/*  www.  j  a  v a2s. c  o m*/
 * Copyright (c) 2008-2011 by Jan Stender, Bjoern Kolbeck,
 *               Zuse Institute Berlin
 *
 * Licensed under the BSD License, see LICENSE file for details.
 *
 */

public class Main {
    /**
     * Formats number of seconds to a string consists of number of seconds, minutes, hours or days and the
     * corresponding entity (e.g. "3 minutes" if seconds is between 180 and 239).
     * 
     * @param seconds
     * @return
     */
    public static String SecondsToString(long seconds) {
        String timeString = null;
        if (seconds < 60) {
            // seconds less than one minute
            timeString = seconds + " seconds";
        } else if (seconds < 3600) {
            // seconds less than one hour
            timeString = (seconds / 60) + " minutes";
        } else if (seconds < 86400) {
            // seconds less than one day
            timeString = (seconds / 3600) + " hours";
        } else {
            // seconds equals or longer than one day
            timeString = (seconds / 86400) + " days";
        }
        return timeString;
    }
}

Related

  1. secondsToInternal(int seconds)
  2. secondsToNanoseconds(long seconds)
  3. secondsToReadableBiggest(int seconds)
  4. secondsToString(int seconds)
  5. secondsToString(long seconds)
  6. secondsToString(long seconds)
  7. secondsToString(long time)
  8. secondsToStringWithUnits(double value)
  9. secondsToTicks(double seconds)