Java Milliseconds getMillisDisplayable(long millis)

Here you can find the source of getMillisDisplayable(long millis)

Description

get Millis Displayable

License

Open Source License

Declaration

public static String getMillisDisplayable(long millis) 

Method Source Code

//package com.java2s;
/*//from  w w  w.j a va2  s . c  o m
 *   Copyright 2008-2011 Follett Software Company 
 *
 *   This file is part of PerfMon4j(tm).
 *
 *    Perfmon4j is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU Lesser General Public License, version 3,
 *    as published by the Free Software Foundation.  This program is distributed
 *    WITHOUT ANY WARRANTY OF ANY KIND, WITHOUT AN IMPLIED WARRANTY OF MERCHANTIBILITY,
 *    OR FITNESS FOR A PARTICULAR PURPOSE.  You should have received a copy of the GNU Lesser General Public 
 *    License, Version 3, along with this program.  If not, you can obtain the LGPL v.s at 
 *    http://www.gnu.org/licenses/
 *    
 *    perfmon4j@fsc.follett.com
 *    David Deuchert
 *    Follett Software Company
 *    1391 Corporate Drive
 *    McHenry, IL 60050
 * 
*/

public class Main {
    public static String getMillisDisplayable(long millis) {
        String result = null;
        final long second = 1000;
        final long minute = 60 * second;

        if (millis % minute == 0) {
            long minutes = millis / minute;
            if (minutes == 1) {
                result = minutes + " minute";
            } else {
                result = minutes + " minutes";
            }
        } else if (millis % second == 0) {
            long seconds = millis / second;
            if (seconds == 1) {
                result = seconds + " second";
            } else {
                result = seconds + " seconds";
            }
        } else {
            result = millis + " ms";
        }

        return result;
    }
}

Related

  1. getMillis(long ticks)
  2. getMillis(long timeInMinutes)
  3. getMillis(String _cal)
  4. getMillis(String dateStr)
  5. getMillis(String decimal)
  6. getMilliSecond(Date d1, Date d2)
  7. getMillisecond(Date date)
  8. getMillisecond(String forDate)
  9. getMilliSecondBetween(long start, long end)