Java Time to String timeToString(final long time)

Here you can find the source of timeToString(final long time)

Description

time To String

License

Open Source License

Declaration

public static String timeToString(final long time) 

Method Source Code

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

public class Main {
    public static final long SECOND = 1000;
    public static final long MINUTE = SECOND * 60;
    public static final long HOUR = MINUTE * 60;
    public static final long DAY = HOUR * 24;

    public static String timeToString(final long time) {
        long timeRemaining = time;
        String timeString = "";
        if (timeRemaining >= DAY) {
            final int days = (int) (timeRemaining / DAY);
            timeString = timeString.concat(days + (days == 1 ? " day " : " days "));
            timeRemaining -= days * DAY;
        }//from ww  w  . j ava 2s .  co  m
        if (timeRemaining >= HOUR) {
            final int hours = (int) (timeRemaining / HOUR);
            timeString = timeString.concat(hours + (hours == 1 ? " hour " : " hours "));
            timeRemaining -= hours * HOUR;
        }
        if (timeRemaining >= MINUTE) {
            final int minutes = (int) (timeRemaining / MINUTE);
            timeString = timeString.concat(minutes + (minutes == 1 ? " minute " : " minutes "));
            timeRemaining -= minutes * MINUTE;
        }
        if (timeRemaining >= SECOND) {
            final int seconds = (int) (timeRemaining / SECOND);
            timeString = timeString.concat(seconds + (seconds == 1 ? " second " : " seconds "));
            timeRemaining -= seconds * SECOND;
        }
        return timeString;
    }
}

Related

  1. timeToString(Date d, String tzString)
  2. timeToString(Date date)
  3. timeToString(double d)
  4. timeToString(double time, boolean longNames)
  5. timeToString(final Date date)
  6. timeToString(int s)
  7. timeToString(int time)
  8. timeToString(int time)
  9. timeToString(int time)