Java Second Format formatMinutesSeconds(final long sourceDuration, final TimeUnit sourceUnit)

Here you can find the source of formatMinutesSeconds(final long sourceDuration, final TimeUnit sourceUnit)

Description

Formats the specified duration in 'mm:ss.SSS' format.

License

Apache License

Parameter

Parameter Description
sourceDuration the duration to format
sourceUnit the unit to interpret the duration

Return

representation of the given time data in minutes/seconds

Declaration

public static String formatMinutesSeconds(final long sourceDuration, final TimeUnit sourceUnit) 

Method Source Code

//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));
    }
}

Related

  1. compareDate(String fistDate, String secondDate, String format)
  2. elapsedSeconds(long startTime)
  3. elapsedSeconds2(long milli)
  4. formatMiliSeconds(long time)
  5. formatMilliIntervalAsSeconds(long interval)
  6. formatNanoseconds (final long ns)
  7. formatSecondFractions(long numUnits, int denominator)
  8. formatSeconds(double seconds)
  9. formatSeconds(double seconds)