Java Millisecond Convert millisToString(long t)

Here you can find the source of millisToString(long t)

Description

millis To String

License

Apache License

Declaration

public static String millisToString(long t) 

Method Source Code

//package com.java2s;
/**/*from w  ww  . java2 s.c o  m*/
 * Copyright 2014-2017 Functional Genomics Development Team, European Bioinformatics Institute
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations under the License.
 *
 * @author Mikhail Gostev <gostev@gmail.com>
 **/

public class Main {
    public static String millisToString(long t) {
        StringBuilder sb = new StringBuilder();

        long frac = t / 3600000L;

        if (frac > 0) {
            sb.append(frac).append("h");
            t = t - frac * 3600000;
        }

        frac = t / 60000;

        if (frac > 0) {
            if (sb.length() > 0) {
                sb.append(' ');
            }

            sb.append(frac).append("m");
            t = t - frac * 60000;
        }

        frac = t / 1000;

        if (frac > 0) {
            if (sb.length() > 0) {
                sb.append(' ');
            }

            sb.append(frac).append("s");
            t = t - frac * 1000;
        }

        if (t > 0) {
            if (sb.length() > 0) {
                sb.append(' ');
            }

            sb.append(t).append("ms");
        }

        return sb.toString();
    }
}

Related

  1. millisToSeconds(long millis)
  2. millisToShortDHMS(long duration)
  3. millisToString(float millis)
  4. millisToString(long millis)
  5. millisToString(long ms)
  6. millisToStringDouble(double millis)
  7. millisToText(long millis)
  8. millisToTime(final long time)
  9. millisToTime(float millis)