Here you can find the source of durationToString(long millis)
Parameter | Description |
---|---|
millis | a parameter |
public static String durationToString(long millis)
//package com.java2s; /******************************************************************************* * Copyright (c) 2009, 2016 GreenVulcano ESB Open Source Project. * All rights reserved.// w w w . jav a2 s. c om * * This file is part of GreenVulcano ESB. * * GreenVulcano ESB is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * GreenVulcano ESB 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with GreenVulcano ESB. If not, see <http://www.gnu.org/licenses/>. *******************************************************************************/ import java.util.concurrent.TimeUnit; public class Main { /** * Convert a long representing a ms duration into a string in the format HH:mm:ss.SSS. * * @param millis * @return */ public static String durationToString(long millis) { long h = TimeUnit.MILLISECONDS.toHours(millis); millis -= TimeUnit.HOURS.toMillis(h); long m = TimeUnit.MILLISECONDS.toMinutes(millis); millis -= TimeUnit.MINUTES.toMillis(m); long s = TimeUnit.MILLISECONDS.toSeconds(millis); millis -= TimeUnit.SECONDS.toMillis(s); return String.format("%d:%02d:%02d.%03d", h, m, s, millis); } }