Java Day of getIntervalDays(Date fDate, Date oDate)

Here you can find the source of getIntervalDays(Date fDate, Date oDate)

Description

get Interval Days

License

Open Source License

Declaration

public static int getIntervalDays(Date fDate, Date oDate) throws ParseException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

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

import java.util.Date;

public class Main {

    public static int getIntervalDays(Date fDate, Date oDate) throws ParseException {
        String fDate1 = toString(fDate, "yyyyMMdd");
        String oDate1 = toString(oDate, "yyyyMMdd");
        java.text.SimpleDateFormat df = new java.text.SimpleDateFormat("yyyyMMdd");
        java.util.Date cDate = df.parse(fDate1);
        java.util.Date dDate = df.parse(oDate1);
        return (int) ((cDate.getTime() - dDate.getTime()) / (24 * 60 * 60 * 1000));
    }//ww  w .  jav  a2  s. c  o  m

    public static String toString(Date date, String format) {
        if (date != null) {
            SimpleDateFormat dateformatter = new SimpleDateFormat(format);
            String dateString = dateformatter.format(date);
            return dateString;
        } else {
            return null;
        }
    }
}

Related

  1. getFormattedNowDatePlusDays(int days, String dateFormat)
  2. getFullAge(Date birthday)
  3. getIncrementDaysSecond(String strDate, int sec)
  4. getInsertDayDate(int days)
  5. getIntervalDate(String date, int intervalDays)
  6. getIntevalDays(String startDate, String endDate)
  7. getLateInTheDay(Date date)
  8. getLatest7Day()
  9. getNDayAfterCurrentDate(String dateStr, String dateFormat, int n)