format During - Java java.util

Java examples for java.util:Date Format

Description

format During

Demo Code


//package com.java2s;
import java.util.Date;

public class Main {
    public static void main(String[] argv) throws Exception {
        long mss = 2;
        System.out.println(formatDuring(mss));
    }// ww w.  java2 s  .  co  m

    public static String formatDuring(long mss) {
        long minutes = 40;
        long seconds = 0;
        if (mss > 0) {
            minutes = mss / (1000 * 60);
            seconds = (mss - (minutes * (1000 * 60))) / 1000;
        }
        String strminutes = String.valueOf(minutes);
        if (minutes < 100) {
            strminutes = String.format("%02d", minutes);
        }
        String strseconds = String.format("%02d", seconds);
        return strminutes + ":" + strseconds;
    }

    public static String formatDuring(Date begin, Date end) {
        return formatDuring(end.getTime() - begin.getTime());
    }
}

Related Tutorials