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

Declaration

public static int getDiffDays(String startDate, String endDate) 

Method Source Code

//package com.java2s;

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  w w.ja va  2  s .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. dayDiff(Date date1, Date date2)
  2. dayOffset(Date date, int offset)
  3. daysBetweenDate(Date date1, Date date2)
  4. getDiff(String startTime, String endTime)
  5. getDiff(String startTime, String endTime)
  6. getDiffDays(String startDate, String endDate)
  7. getDiffHour(String startTime, String endTime)
  8. getDiffHour(String startTime, String endTime)
  9. getFragment(Calendar calendar, int fragment, int unit)