Java Second timeFromSeconds(long ms)

Here you can find the source of timeFromSeconds(long ms)

Description

time From Seconds

License

Open Source License

Declaration

public static String timeFromSeconds(long ms) 

Method Source Code

//package com.java2s;

public class Main {
    public static String timeFromSeconds(long ms) {
        StringBuilder sb = new StringBuilder(40);

        if (ms / 628992000 > 0) {
            long years = ms / 628992000;
            sb.append(years + (years == 1 ? " year " : " years "));
            ms -= years * 628992000;//w ww.j av  a  2  s. c  o m
        }

        if (ms / 2620800 > 0) {
            long months = ms / 2620800;
            sb.append(months + (months == 1 ? " month " : " months "));
            ms -= months * 2620800;
        }

        if (ms / 604800 > 0) {
            long weeks = ms / 604800;
            sb.append(weeks + (weeks == 1 ? " week " : " weeks "));
            ms -= weeks * 604800;
        }

        if (ms / 86400 > 0) {
            long days = ms / 86400;
            sb.append(days + (days == 1 ? " day " : " days "));
            ms -= days * 86400;
        }

        if (ms / 3600 > 0) {
            long hours = ms / 3600;
            sb.append(hours + (hours == 1 ? " hour " : " hours "));
            ms -= hours * 3600;
        }

        if (ms / 60 > 0) {
            long minutes = ms / 60;
            sb.append(minutes + (minutes == 1 ? " minute " : " minutes "));
            ms -= minutes * 60;
        }

        if (ms > 0) {
            sb.append(ms + " seconds ");
        }

        if (sb.length() > 1) {
            sb.replace(sb.length() - 1, sb.length(), "");
        } else {
            sb = new StringBuilder("null");
        }

        return sb.toString();
    }
}

Related

  1. ticksWithSecondsSetTo(long ticks, int seconds)
  2. timecents2seconds(int timecents)
  3. timeDecimalSeconds(String time)
  4. timeElapsedSecond(long prevTime, long curTime, long periodSecond)
  5. timeFromSeconds(int timeInSec)
  6. timeSpanInSeconds(long time1, long time2)
  7. timeStampSeconds()
  8. timeStringToSeconds(String input)
  9. timeStringToSeconds(String time)