Here you can find the source of convertTimeToString(double d, String timeFormat)
Parameter | Description |
---|---|
d | time in double. |
timeFormat | Format string e.g. "%02d:%02d:%02f" or use predefined constants SEC_TIME_FORMAT, DURATION_TIME_FORMAT. |
public static String convertTimeToString(double d, String timeFormat)
//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(); } }