Java Time Format formatTime2(long secs)

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

Description

format Time

License

Artistic License

Declaration

public static String formatTime2(long secs) 

Method Source Code

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

public class Main {
    public static String formatTime2(long secs) {
        StringBuffer rv = new StringBuffer();

        int seconds = (int) secs, minutes = 0, hours = 0, days = 0;

        days = seconds / (60 * 60 * 24);
        hours = seconds / (60 * 60) % 24;
        minutes = (seconds / 60) % 60;//  www.ja va2 s . c  om
        seconds = seconds % 60;

        if (days > 0) {
            rv.append(days);
            rv.append(":");
        }

        if (hours > 0) {
            if (hours < 10)
                rv.append("0");
            rv.append(hours);

            rv.append(":");
        }

        if (minutes > 0) {
            if (minutes < 10)
                rv.append("0");
            rv.append(minutes);

            rv.append(":");
        }

        if (seconds < 10)
            rv.append("0");
        rv.append(seconds);

        return rv.toString();
    }
}

Related

  1. formatTime(String time)
  2. formatTime(String time)
  3. formatTime(String time)
  4. formatTime(String timeStr)
  5. formatTime14To12String(String time)
  6. formatTime2(long timeInSeconds)
  7. formatTime3(long secs)
  8. formatTimeAgo(int seconds)
  9. formatTimeArea(Integer hour)