number Of Days Between Calendar - Java java.util

Java examples for java.util:Day

Description

number Of Days Between Calendar

Demo Code


//package com.java2s;

import java.util.Calendar;

public class Main {
    public static void main(String[] argv) throws Exception {
        Calendar start = Calendar.getInstance();
        Calendar end = Calendar.getInstance();
        System.out.println(numberOfDaysBetween(start, end));
    }/*  w  ww .  java  2  s . c  o m*/

    private static long numberOfMSInADay = 1000 * 60 * 60 * 24;

    public static int numberOfDaysBetween(Calendar start, Calendar end) {

        long span = end.getTimeInMillis() - start.getTimeInMillis();
        return (int) (span / numberOfMSInADay);
    }
}

Related Tutorials