Java Day of getIntevalDays(String startDate, String endDate)

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

Description

get Inteval Days

License

Apache License

Declaration

public static long getIntevalDays(String startDate, String endDate) 

Method Source Code


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

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class Main {
    public final static String YYYY_MM_DD = "yyyy-MM-dd";

    public static long getIntevalDays(String startDate, String endDate) {
        try {/*from w w w. ja  va  2 s . co m*/
            return getIntevalDays(parse(startDate, YYYY_MM_DD), parse(endDate, YYYY_MM_DD));
        } catch (Exception ee) {
            return 0l;
        }
    }

    public static long getIntevalDays(Date startDate, Date endDate) {
        try {
            Calendar startCalendar = Calendar.getInstance();
            Calendar endCalendar = Calendar.getInstance();

            startCalendar.setTime(startDate);
            endCalendar.setTime(endDate);
            long diff = endCalendar.getTimeInMillis() - startCalendar.getTimeInMillis();

            return (diff / (1000 * 60 * 60 * 24));
        } catch (Exception ee) {
            return 0l;
        }
    }

    public static Date parse(String strDate, String pattern) throws ParseException {
        try {
            return getFormatter(pattern).parse(strDate);
        } catch (ParseException pe) {
            throw new ParseException("Method parse in Class DateUtil err: parse strDate fail.",
                    pe.getErrorOffset());
        }
    }

    private static SimpleDateFormat getFormatter(String parttern) {
        return new SimpleDateFormat(parttern);
    }
}

Related

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