Java Time Format formatTime3(long secs)

Here you can find the source of formatTime3(long secs)

Description

format Time

License

Artistic License

Declaration

public static String formatTime3(long secs) 

Method Source Code

//package com.java2s;
//License from project: Artistic License 

public class Main {
    public static String formatTime3(long secs) {
        int seconds = (int) secs;
        int minutes = 0;
        int hours = 0;
        int days = 0;

        days = seconds / (60 * 60 * 24);
        hours = seconds / (60 * 60) % 24;
        minutes = (seconds / 60) % 60;/*from  w ww  . j  a v  a 2  s  .  co m*/
        seconds %= 60;

        StringBuffer buf = new StringBuffer();
        if (days > 0)
            buf.append(days).append(days != 1 ? " days, " : " day, ");
        if (days > 0 || hours > 0)
            buf.append(hours).append(hours != 1 ? " hours, " : " hour, ");
        if (hours > 0 || minutes > 0)
            buf.append(minutes).append(minutes != 1 ? " minutes, " : " minute, ");

        buf.append(seconds).append(seconds != 1 ? " seconds" : " second");

        return buf.toString();
    }
}

Related

  1. formatTime(String time)
  2. formatTime(String timeStr)
  3. formatTime14To12String(String time)
  4. formatTime2(long secs)
  5. formatTime2(long timeInSeconds)
  6. formatTimeAgo(int seconds)
  7. formatTimeArea(Integer hour)
  8. formatTimeDeltaValue(long delta)
  9. formatTimeDiff(long finishTime, long startTime)