days Between - Java java.util

Java examples for java.util:Day

Description

days Between

Demo Code


//package com.java2s;

import java.util.Date;

public class Main {
    public static double daysBetween(Date date1, Date date2) {
        return hoursBetween(date1, date2) / 24;
    }/*  w  w  w.j  a  v  a  2s.c  om*/

    public static double hoursBetween(Date date1, Date date2) {
        return minutesBetween(date1, date2) / 60;
    }

    public static double minutesBetween(Date date1, Date date2) {
        long gapInMilliseconds = date2.getTime() - date1.getTime();
        return Math.abs(gapInMilliseconds / (double) (1000 * 60));
    }
}

Related Tutorials