Java Millisecond Format milliSecondsToFormatedString(long timeMillis)

Here you can find the source of milliSecondsToFormatedString(long timeMillis)

Description

milli Seconds To Formated String

License

Open Source License

Declaration

public static final String milliSecondsToFormatedString(long timeMillis) 

Method Source Code

//package com.java2s;
/*// ww  w.ja v a  2 s. c  o m
 * Copyright (c) 2004-2013 Universidade do Porto - Faculdade de Engenharia
 * Laborat?rio de Sistemas e Tecnologia Subaqu?tica (LSTS)
 * All rights reserved.
 * Rua Dr. Roberto Frias s/n, sala I203, 4200-465 Porto, Portugal
 *
 * This file is part of Neptus, Command and Control Framework.
 *
 * Commercial Licence Usage
 * Licencees holding valid commercial Neptus licences may use this file
 * in accordance with the commercial licence agreement provided with the
 * Software or, alternatively, in accordance with the terms contained in a
 * written agreement between you and Universidade do Porto. For licensing
 * terms, conditions, and further information contact lsts@fe.up.pt.
 *
 * European Union Public Licence - EUPL v.1.1 Usage
 * Alternatively, this file may be used under the terms of the EUPL,
 * Version 1.1 only (the "Licence"), appearing in the file LICENCE.md
 * included in the packaging of this file. You may not use this work
 * except in compliance with the Licence. Unless required by applicable
 * law or agreed to in writing, software distributed under the Licence is
 * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF
 * ANY KIND, either express or implied. See the Licence for the specific
 * language governing permissions and limitations at
 * https://www.lsts.pt/neptus/licence.
 *
 * For more information please see <http://lsts.fe.up.pt/neptus>.
 *
 * Author: Paulo Dias
 * 2008/04/16
 */

public class Main {
    public static final String milliSecondsToFormatedString(long timeMillis) {
        double time = timeMillis / 1000.0;
        //time = 3*60*60 + 2*60;
        String tt = "";
        if (time < 60)
            tt = new Double(time).doubleValue() + " s";
        else if ((time / 60.0) < 60) {
            long mi = (long) (time / 60.0);
            long sec = (long) (time % 60.0);
            tt = mi + "m " + ((sec < 10) ? "0" : "") + sec + "s";
        } else if ((time / 60.0 / 60.0) < 24) {
            long hr = (long) (time / 60.0 / 60.0);
            long mi = (long) ((time / 60.0) % 60.0);
            tt = hr + "h " + ((mi < 10) ? "0" : "") + mi + "m";
        } else {
            long dy = (long) (time / 60.0 / 60.0 / 24.0);
            long hr = (long) ((time / 60.0 / 60.0) % 24);
            long mi = (long) ((time / 60.0) % 60.0);
            tt = dy + "d " + ((hr < 10) ? "0" : "") + hr + "h " + ((mi < 10) ? "0" : "") + mi + "m";
        }
        return tt;
    }
}

Related

  1. millis2String(long n)
  2. millisAsTicks(int ms)
  3. milliseconds2String(long millis)
  4. millisecondsPerTick(final int tps)
  5. milliSecondsSince(long startMillis)
  6. millisecondsToToTimeFormat(long inMs)
  7. milliSekundsToTime(long millisecond)
  8. millisOf(long timestamp)
  9. millisPerBeat(final float bpm)