Java Time Format formatTime(long time)

Here you can find the source of formatTime(long time)

Description

format Time

License

Open Source License

Declaration

public static String formatTime(long time) 

Method Source Code

//package com.java2s;

public class Main {
    public static final long TIME_SECOND = 1000;
    public static final long TIME_MINUTE = TIME_SECOND * 60;
    public static final long TIME_HOUR = TIME_MINUTE * 60;
    public static final long TIME_DAY = TIME_HOUR * 24;
    public static final long TIME_YEAR = TIME_DAY * 365;

    public static String formatTime(long time) {
        if (time <= 0) {
            return "now";
        } else if (time < TIME_SECOND) {
            return time + "ms";
        } else if (time < TIME_MINUTE) {
            return (time / TIME_SECOND) + "s";
        } else if (time < TIME_HOUR) {
            return (time / TIME_MINUTE) + "m " + formatTime(time % TIME_MINUTE);
        } else if (time < TIME_DAY) {
            return (time / TIME_HOUR) + "h " + formatTime(time % TIME_HOUR);
        } else if (time < TIME_YEAR) {
            return (time / TIME_DAY) + "d " + formatTime(time % TIME_DAY);
        } else {//from  www.  j a  v  a 2 s .c o  m
            return (time / TIME_YEAR) + "y " + formatTime(time % TIME_YEAR);
        }
    }
}

Related

  1. formatTime(long sec)
  2. formatTime(long seconds)
  3. formatTime(long seconds)
  4. formatTime(long seconds)
  5. formatTime(long time)
  6. formatTime(long time)
  7. formatTime(long time)
  8. formatTime(long time)
  9. formatTime(long time)