Java Date Difference getDiffDays(Date from, Date to)

Here you can find the source of getDiffDays(Date from, Date to)

Description

get Diff Days

License

Apache License

Declaration

public static long getDiffDays(Date from, Date to) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.*;

public class Main {

    public static long getDiffDays(String startStr, String endStr) {
        GregorianCalendar start = getGregorianCalendar(startStr);
        GregorianCalendar end = getGregorianCalendar(endStr);
        return (start.getTime().getTime() - end.getTime().getTime()) / 86400000;
    }/*from  w  w w . j  a v a 2 s .c o  m*/

    public static long getDiffDays(Date from, Date to) {
        return (to.getTime() - from.getTime()) / 86400000;
    }

    public static GregorianCalendar getGregorianCalendar(String yyyymmdd) {
        int yyyy = Integer.parseInt(yyyymmdd.substring(0, 4));
        int mm = Integer.parseInt(yyyymmdd.substring(4, 6));
        int dd = Integer.parseInt(yyyymmdd.substring(6, 8));
        GregorianCalendar calendar = new GregorianCalendar(yyyy, mm - 1, dd, 0, 0, 0);
        return calendar;
    }
}

Related

  1. getDateDifference(String startDateString, String endDateString)
  2. getDateDiffHour(String begindate, String enddate)
  3. getDayDiff(Date firstDate, Date secondDate)
  4. getDiff(Date from, Date to)
  5. getDiffDate(String srcDate, String format, int diff)
  6. getDiffDays2(Date one, Date two)
  7. getDifference(Date a, Date b)
  8. getDifference(String dateStr1, String dateStr2, char choice)
  9. getDifferenceInDays(Calendar calendar0, Calendar calendar1)