Java Day Between getDiffDays(String startDate, String endDate)

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

Description

get Diff Days

License

Open Source License

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  www.  ja v  a 2 s.  c om*/
        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. getDaysBetweenDate(Date begin, Date end)
  2. getDaysDiff(Date startDate, Date endDate)
  3. getDaysDifference(final Date begin, final Date end)
  4. getDiffBetweenQuarter(Date latestDate, Date current)
  5. getDiffDays(Date date1, Date date2)
  6. getDifferDays(Date d1, Date d2)
  7. getDifferDays(String date1, String date2)
  8. getDifference(Date d1, Date d2)
  9. getDifferenceInDays(final Date startDate, final Date endDate)