Here you can find the source of formatMinutesSeconds(final long sourceDuration, final TimeUnit sourceUnit)
Parameter | Description |
---|---|
sourceDuration | the duration to format |
sourceUnit | the unit to interpret the duration |
public static String formatMinutesSeconds(final long sourceDuration, final TimeUnit sourceUnit)
//package com.java2s; /**// w ww . jav a 2s.c om * Copyright (C) 2016 Hurence (support@hurence.com) * * 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. */ import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; import java.util.concurrent.TimeUnit; public class Main { /** * Formats the specified duration in 'mm:ss.SSS' format. * * @param sourceDuration the duration to format * @param sourceUnit the unit to interpret the duration * @return representation of the given time data in minutes/seconds */ public static String formatMinutesSeconds(final long sourceDuration, final TimeUnit sourceUnit) { final long millis = TimeUnit.MILLISECONDS.convert(sourceDuration, sourceUnit); final SimpleDateFormat formatter = new SimpleDateFormat("mm:ss.SSS", Locale.US); return formatter.format(new Date(millis)); } }