Java Date Difference getDateDiffDay(String begindate, String enddate)

Here you can find the source of getDateDiffDay(String begindate, String enddate)

Description

get Date Diff Day

License

Apache License

Declaration

public static long getDateDiffDay(String begindate, String enddate) 

Method Source Code

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

import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.GregorianCalendar;

public class Main {
    public static long getDateDiffDay(String begindate, String enddate) {
        long hourDiff = getDateDiffHour(begindate, enddate);
        Float dayDiff = (float) (hourDiff / 24);
        return dayDiff.intValue();
    }/*from  ww w.  ja  va2s .  c o m*/

    public static long getDateDiffDay(String begindate) {
        GregorianCalendar thisday = new GregorianCalendar();
        SimpleDateFormat shortFormatter = new SimpleDateFormat("yyyy-MM-dd");
        String thisdateStr = shortFormatter.format(thisday.getTime());

        return getDateDiffDay(begindate, thisdateStr);
    }

    public static long getDateDiffHour(String begindate, String enddate) {
        long minuteDiff = getDateDiffMinute(begindate, enddate);
        Float hourDiff = (float) (minuteDiff / 60);
        return hourDiff.intValue();
    }

    public static long getDateDiffMinute(String begindate, String enddate) {
        SimpleDateFormat formatter = new SimpleDateFormat(
                "yyyy-MM-dd kk:mm:ss");
        ParsePosition pos1 = new ParsePosition(0);
        ParsePosition pos2 = new ParsePosition(0);
        if (begindate.length() == 10)
            begindate = begindate + " 00:00:00";
        if (enddate.length() == 10)
            enddate = enddate + " 00:00:00";
        Date BeginDate = formatter.parse(begindate, pos1);
        Date EndDate = formatter.parse(enddate, pos2);
        long dateDiff = EndDate.getTime() - BeginDate.getTime();
        Float minuteDiff = (float) (dateDiff / 1000 / 60);
        return minuteDiff.intValue();
    }
}

Related

  1. diffOfDate(String begin, String end)
  2. diffY(Date endDate, Date startDate)
  3. getDateDiff(String startDate, String endDate)
  4. getDateDiff(String startDt, String endDt)
  5. getDateDiff(String startTime, String endTime)
  6. getDateDifference(String start, String end)
  7. getDateDifference(String startDateString, String endDateString)
  8. getDateDiffHour(String begindate, String enddate)
  9. getDayDiff(Date firstDate, Date secondDate)