Java Time Format getFormattedDuration(long fromTime)

Here you can find the source of getFormattedDuration(long fromTime)

Description

get Formatted Duration

License

Open Source License

Declaration

public static String getFormattedDuration(long fromTime) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2006-2007, Cloudsmith Inc.
 * The code, documentation and other materials contained herein have been
 * licensed under the Eclipse Public License - v 1.0 by the copyright holder
 * listed above, as the Initial Contributor under such license. The text of
 * such license is available at www.eclipse.org.
 ******************************************************************************/

import java.text.MessageFormat;

public class Main {
    private static final MessageFormat TIME_FORMAT = new MessageFormat("{0}{1}");
    private static final int MS_IN_SECOND = 1000;
    private static final int SEC_IN_MINUTE = 60;

    public static String getFormattedDuration(long fromTime) {
        long milliseconds = getDuration(fromTime);
        long seconds = milliseconds / MS_IN_SECOND;
        long minutes = seconds / SEC_IN_MINUTE;
        Object[] args = { Long.valueOf(minutes), Long.valueOf(seconds % SEC_IN_MINUTE) };

        return TIME_FORMAT.format(args);
    }//from w w  w  .j a  v  a  2 s  .  c o m

    public static long getDuration(long fromTime) {
        return System.currentTimeMillis() - fromTime;
    }
}

Related

  1. getFormattedCurrentDateAndTime()
  2. getFormattedCurrentDateTime(String pattern)
  3. getFormattedDateAndTime(final Date date)
  4. getFormattedDateTime(Date date, String pattern)
  5. getFormattedDateTime(String date, String dateFormat)
  6. getFormattedFileTime(File f, String format)
  7. getFormattedTime()
  8. getFormattedTime(Date date)
  9. getFormattedTime(Date date)