Java Utililty Methods Day Count

List of utility methods to do Day Count

Description

The list of methods to do Day Count are organized into topic(s).

Method

intgetDayCount(String from, String to)
get Day Count
long duration = getTimeCount(from, to, DATE_FORMAT.toPattern());
return (int) (duration / (1000 * 60 * 60 * 24));
intgetDayCount(String from, String to)
get Day Count
return getDayCountWithFormatter(from, to, "yyyyMMdd");
intgetDayCount(String yyyy_mm_dd_1, String yyyy_mm_dd_2)
get Day Count
SimpleDateFormat myFormatter = new SimpleDateFormat("yyyy-MM-dd");
Date date = myFormatter.parse(yyyy_mm_dd_1);
Date mydate = myFormatter.parse(yyyy_mm_dd_2);
return (int) ((date.getTime() - mydate.getTime()) / (24 * 60 * 60 * 1000));
LonggetDaySub(String beginDate, String endDate)
get Day Sub
Long days = 0L;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
days = (sdf.parse(endDate).getTime() - sdf.parse(beginDate).getTime()) / (24 * 60 * 60 * 1000);
return days;
longgetDaySub(String start_time, String end_time)
get Day Sub
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
long day = 0;
try {
    long start_timeStamp = sdf.parse(start_time).getTime();
    long end_timeStamp = sdf.parse(end_time).getTime();
    day = (end_timeStamp - start_timeStamp) / (24 * 60 * 60 * 1000);
} catch (ParseException e) {
    e.printStackTrace();
...
intgetDaysBetween(Calendar d1, Calendar d2)
get Days Between
if (d1.after(d2)) { 
    Calendar swap = d1;
    d1 = d2;
    d2 = swap;
int days = d2.get(Calendar.DAY_OF_YEAR) - d1.get(Calendar.DAY_OF_YEAR);
int y2 = d2.get(Calendar.YEAR);
if (d1.get(Calendar.YEAR) != y2) {
...
intgetDaysBetween(Map params)
get Days Between
String start = params.get("start_date").toString();
String end = params.get("end_date").toString();
Calendar startCalendar = Calendar.getInstance();
Calendar endCalendar = Calendar.getInstance();
Date startDate = null;
Date endDate = null;
try {
    startDate = new SimpleDateFormat("yy-MM-dd").parse(start);
...
StringgetDaysBetweenTwoDays(String dateFrom, String dateEnd)
get Days Between Two Days
Date dtFrom = null;
Date dtEnd = null;
dtFrom = toDate(dateFrom, "yyyy-MM-dd");
dtEnd = toDate(dateEnd, "yyyy-MM-dd");
long begin = dtFrom.getTime();
long end = dtEnd.getTime();
long inter = end - begin;
if (inter < 0) {
...
longGetDays(String strStartDate, String strEndDate)
Get Days
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
Date d1 = df.parse(strStartDate);
Date d2 = df.parse(strEndDate);
long diff = d2.getTime() - d1.getTime();
return diff / (1000 * 60 * 60 * 24);