Java Time Elapsed elapsedTime(long ms)

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

Description

elapsed Time

License

Open Source License

Declaration

public static String elapsedTime(long ms) 

Method Source Code

//package com.java2s;
/*  Copyright (C) 2009 Mobile Sorcery AB
    /*from   w w  w  .  j a v  a2 s  .com*/
This program is free software; you can redistribute it and/or modify it
under the terms of the Eclipse Public License v1.0.
    
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 Eclipse Public License v1.0 for
more details.
    
You should have received a copy of the Eclipse Public License v1.0 along
with this program. It is also available at http://www.eclipse.org/legal/epl-v10.html
*/

public class Main {
    public static String elapsedTime(long ms) {
        String unit = "ms";
        long value = ms;
        long rem = 0;
        if (ms >= 3600000) {
            unit = "h";
            value = ms / 3600000;
            rem = ms % 3600000;
        } else if (ms >= 60000) {
            unit = "m";
            value = ms / 60000;
            rem = ms % 60000;
        } else if (ms >= 1000) {
            unit = "s";
            value = ms / 1000;
            rem = ms % 1000;
        }
        String minor = rem == 0 ? "" : " " + elapsedTime(rem);
        return value + unit + minor;
    }
}

Related

  1. elapsedMicros(String startTime, String endTime)
  2. elapsedNanos(long nanoseconds)
  3. elapsedNanos(long startNanoTime)
  4. elapsedTime(long endTime, long beginTime)
  5. elapsedTime(long milli)
  6. elapsedTime(long startTime, long endTime, double units)
  7. elapsedTime(long timeInMs)
  8. elapsedTimeMs(long start)
  9. elapsedTimeStamp(long time)