Java Millisecond Format format(long millis)

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

Description

format

License

Open Source License

Declaration

public static String format(long millis) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2009, 2016 Xored Software Inc and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *  /*w  w w  .  ja va 2s .  c  o  m*/
 * Contributors:
 *    Xored Software Inc - initial API and implementation and/or initial documentation
 *******************************************************************************/

import java.text.DecimalFormat;

public class Main {
    private static DecimalFormat secondsFormat;

    public static String format(long millis) {
        int mins = 0;
        double secs = 0;
        if (millis != 0) {
            double time = (double) millis / 1000;
            mins = (int) (time / 60);
            secs = time - mins * 60;
        }

        StringBuilder result = new StringBuilder();
        if (mins != 0) {
            result.append(mins);
            result.append(" m "); //$NON-NLS-1$
            result.append((int) secs);
        } else {
            result.append(secondsFormat.format(secs));
        }

        return result.toString();
    }
}

Related

  1. createDateTimeString(final long ms, final DateFormat timeFormat, final String milliSep)
  2. format(final long timeInMillis)
  3. format(long millis)
  4. format(long millis)
  5. format(long millis)
  6. format(long millis, String pattern)
  7. format(long milliseconds, String format)