Java Formatter Usage convertTimeToString(double d, String timeFormat)

Here you can find the source of convertTimeToString(double d, String timeFormat)

Description

Converts time to string.

License

Open Source License

Parameter

Parameter Description
d time in double.
timeFormat Format string e.g. "%02d:%02d:%02f" or use predefined constants SEC_TIME_FORMAT, DURATION_TIME_FORMAT.

Return

Converted String.

Declaration

public static String convertTimeToString(double d, String timeFormat) 

Method Source Code

//package com.java2s;
/*/*from  w  w w .ja  v a2  s. co m*/
 * Universal Media Server, for streaming any medias to DLNA
 * compatible renderers based on the http://www.ps3mediaserver.org.
 * Copyright (C) 2012 UMS developers.
 *
 * This program is a 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; version 2
 * of the License only.
 *
 * 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
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

import java.util.Formatter;
import java.util.Locale;

public class Main {
    /**
     * Converts time to string.
     *
     * @param d time in double.
     * @param timeFormat Format string e.g. "%02d:%02d:%02f" or use predefined constants
     * SEC_TIME_FORMAT, DURATION_TIME_FORMAT.
     *
     * @return Converted String.
     */
    public static String convertTimeToString(double d, String timeFormat) {
        StringBuilder sb = new StringBuilder();
        try (Formatter formatter = new Formatter(sb, Locale.US)) {
            double s = d % 60;
            int h = (int) (d / 3600);
            int m = ((int) (d / 60)) % 60;
            formatter.format(timeFormat, h, m, s);
        }

        return sb.toString();
    }
}

Related

  1. bytesToHexString(byte[] bytes)
  2. byteToHex(final byte[] bytes)
  3. byteToHexWithPrefix(final byte[] data)
  4. chatting(String fmt, Object... args)
  5. convertRGBDecToHex(String decimal)
  6. convertToMillions(double tmp)
  7. createHexadecimalString(byte[] data)
  8. digestToString(byte[] input)
  9. displayStackTrace()