Java Time Format formatTimeInfo(long time)

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

Description

Get size info

License

Open Source License

Parameter

Parameter Description
ms size of file

Declaration

public static String formatTimeInfo(long time) 

Method Source Code

//package com.java2s;
/*/*from w  ww.  j  av  a 2s  .  c o m*/
 * Copyright (C) 2013-2015 E-Spring Tran
 * 
 *             https://espringtran.com
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

public class Main {
    /**
     * Get size info
     * 
     * @param ms
     *            size of file
     * @return
     */
    public static String formatTimeInfo(long time) {
        String info = "";
        long ms = (long) time;
        int i = 1000;
        int value = (int) ms % i;
        info = value + " millisecond(s)";
        ms /= i;
        if (ms > 0) {
            i = 60;
            value = (int) ms % i;
            info = value + " second(s) " + info;
            ms /= i;
        }
        if (ms > 0) {
            i = 60;
            value = (int) ms % i;
            info = value + " minute(s) " + info;
            ms /= i;
        }
        if (ms > 0) {
            i = 24;
            value = (int) ms % i;
            info = value + " hour(s) " + info;
            ms /= i;
        }
        if (ms > 0) {
            i = 30;
            value = (int) ms % i;
            info = value + " day(s) " + info;
            ms /= i;
        }
        if (ms > 0) {
            i = 12;
            value = (int) ms % i;
            info = value + " month(s) " + info;
            ms /= i;
        }
        if (ms > 0) {
            info = ms + " year(s) " + info;
        }
        return info;
    }
}

Related

  1. formatTimeDifference(long ms)
  2. formatTimeDifference(long time1, long time2)
  3. formatTimeDigital(int time)
  4. formatTimeDuringHour(long mss)
  5. formatTimeElapsed(long p_millis)
  6. formatTimeInMilisec(long time)
  7. formatTimeInNanos(long time)
  8. formatTimeInterval(final long time)
  9. formatTimeInterval(long in)