calculate day counts between startDate and endDate - Android java.util

Android examples for java.util:Day

Description

calculate day counts between startDate and endDate

Demo Code

import java.util.Date;

public class Main{
    public static final long SECOND_IN_MILLIS = 1000;
    public static final long MINUTE_IN_MILLIS = SECOND_IN_MILLIS * 60;
    public static final long HOUR_IN_MILLIS = MINUTE_IN_MILLIS * 60;
    public static final long DAY_IN_MILLIS = HOUR_IN_MILLIS * 24;
    public static final long WEEK_IN_MILLIS = DAY_IN_MILLIS * 7;
    /**//from   w  w  w .j  a va 2 s  .  c om
     * calculate day counts between startDate and endDate
     * @param startDate
     * @param endDate
     * @return
     */
    public static int diffDays(Date startDate, Date endDate) {
        return (int) ((endDate.getTime() - startDate.getTime()) / DAY_IN_MILLIS);
    }

}

Related Tutorials