Java Date Difference getDateDiff(String startDt, String endDt)

Here you can find the source of getDateDiff(String startDt, String endDt)

Description

get Date Diff

License

Apache License

Declaration

public static long getDateDiff(String startDt, String endDt) 

Method Source Code


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

import java.text.ParseException;
import java.text.SimpleDateFormat;

public class Main {

    public static long getDateDiff(String startDt, String endDt) {
        return getDateDiff(startDt, endDt, "yyyy-MM-dd");
    }/*from   ww w .  j a  va 2 s.  c o m*/

    public static long getDateDiff(String startDt, String endDt, String pattern) {
        SimpleDateFormat sd = new SimpleDateFormat(pattern);
        long nd = 1000 * 24 * 60 * 60;
        try {
            long diff = sd.parse(endDt).getTime() - sd.parse(startDt).getTime();
            return diff / nd;
        } catch (ParseException e) {
            throw new RuntimeException(e);
        }
    }
}

Related

  1. diffMonth(Date before, Date after)
  2. diffMonth(Date start, Date end)
  3. diffOfDate(String begin, String end)
  4. diffY(Date endDate, Date startDate)
  5. getDateDiff(String startDate, String endDate)
  6. getDateDiff(String startTime, String endTime)
  7. getDateDiffDay(String begindate, String enddate)
  8. getDateDifference(String start, String end)
  9. getDateDifference(String startDateString, String endDateString)