Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import java.util.Date;
import java.util.concurrent.TimeUnit;

public class Main {
    /**
     * Get the difference between 2 date/time values down to millisecond
     * @param startDate
     * @param endDate
     * @param timeUnit
     * @return long - difference between dates based in timeUnit
     */
    public static long calcTimeDifference(Date startDate, Date endDate, TimeUnit timeUnit) {

        long diffInMilliSec = endDate.getTime() - startDate.getTime();
        return timeUnit.convert(diffInMilliSec, timeUnit);
    }
}