Java Millisecond Convert millisecondsToHumanTime(long period)

Here you can find the source of millisecondsToHumanTime(long period)

Description

milliseconds To Human Time

License

Open Source License

Declaration

public static String millisecondsToHumanTime(long period) 

Method Source Code

//package com.java2s;
/*/*from   w ww.j a  va2 s . com*/
     
Copyright IBM Corp. 2010, 2016
This file is part of Anomaly Detection Engine for Linux Logs (ADE).
    
ADE 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.
    
ADE 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 ADE.  If not, see <http://www.gnu.org/licenses/>.
     
*/

public class Main {
    public static final long SECONDS_IN_MINUTE = 60L;
    public static final long MINUTES_IN_HOUR = 60L;
    public static final long MILLIS_IN_SECOND = 1000L;
    public static final long HALF_MILLIS_IN_SECOND = 500L;

    public static String millisecondsToHumanTime(long period) {
        if (period % MILLIS_IN_SECOND >= HALF_MILLIS_IN_SECOND) {
            period += MILLIS_IN_SECOND;
        }
        period /= MILLIS_IN_SECOND;
        long secs = period % SECONDS_IN_MINUTE;
        period /= SECONDS_IN_MINUTE;
        long mins = period % MINUTES_IN_HOUR;
        period /= MINUTES_IN_HOUR;
        long hours = period;
        return String.format("%02d:%02d:%02d (hh:mm:ss)", hours, mins, secs);
    }
}

Related

  1. millisecondsToHHMMSS(long milliseconds)
  2. milliSecondsToHMS(long l)
  3. milliSecondsToHMS(long numMillis)
  4. millisecondsToHuman(long ms)
  5. millisecondsToHumanDateWithSeconds(long milliseconds)
  6. millisecondsToNanoseconds(Long milliseconds)
  7. millisecondsToSeconds(long ms)
  8. millisecondsToSecondsString(long millis)
  9. milliSecondsToString(long interval)