Java Second Format formatTimeSpanSeconds(long span)

Here you can find the source of formatTimeSpanSeconds(long span)

Description

format Time Span Seconds

License

Open Source License

Declaration

public static String formatTimeSpanSeconds(long span) 

Method Source Code

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

public class Main {
    public static String formatTimeSpanSeconds(long span) {
        final int minute = 60;
        final int hour = 60 * 60;
        final int day = 24 * hour;

        if (span < minute) {
            return span + "s";
        } else if (span < hour) {
            return (span / 60) + "m " + (span % 60) + "s";
        } else if (span < day) {
            span = span / 60;/*  w w w. j a v  a  2 s  .  c om*/
            return (span / 60) + "h " + (span % 60) + "m";
        } else {
            long days = span / day;
            long hours = (span % day) / hour;
            long minutes = (span % hour) / minute;
            return days + "d " + hours + "h " + minutes + "m";
        }
    }
}

Related

  1. formatTime(Date d, Locale locale, boolean withSeconds)
  2. formatTime(double seconds)
  3. formatTime(float seconds)
  4. formatTimeInSeconds(int v)
  5. formatTimeSecondsSinceEpoch(final long time, StringBuilder sbuffer)
  6. formatTimeWithOutSeconds(java.util.Date d)
  7. getDHMS(long totalSecond)
  8. getElapsedSeconds(long startTime)
  9. getFormatMSecond(long long_)