Android Date Interval Get getDiffDays(String startDate, String endDate)

Here you can find the source of getDiffDays(String startDate, String endDate)

Description

get Diff Days

License

Apache License

Declaration

public static int getDiffDays(String startDate, String endDate) 

Method Source Code

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

import java.text.ParseException;

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {

    public static int getDiffDays(String startDate, String endDate) {
        long diff = 0;
        SimpleDateFormat ft = null;
        if (startDate.indexOf("/") > 0 && endDate.indexOf("/") > 0) {
            ft = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
        }//from   w  ww  .  jav  a  2s  . co m
        if (startDate.indexOf("-") > 0 && endDate.indexOf("-") > 0) {
            ft = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        }
        try {
            Date sDate = ft.parse(startDate + " 00:00:00");
            Date eDate = ft.parse(endDate + " 00:00:00");
            diff = eDate.getTime() - sDate.getTime();
            diff = diff / 86400000;// 1000*60*60*24;
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return (int) diff;

    }
}

Related

  1. dayOffset(Date date, int offset)
  2. daysBetweenDate(Date date1, Date date2)
  3. getDiff(String startTime, String endTime)
  4. getDiff(String startTime, String endTime)
  5. getDiffDays(String startDate, String endDate)
  6. getDiffHour(String startTime, String endTime)
  7. getDiffHour(String startTime, String endTime)
  8. getFragment(Calendar calendar, int fragment, int unit)
  9. getFragment(Date date, int fragment, int unit)