Java Utililty Methods Date Between

List of utility methods to do Date Between

Description

The list of methods to do Date Between are organized into topic(s).

Method

longdaysBetween2Dates(Date startDate, Date endDate)
days Between Dates
Calendar startDateCal = Calendar.getInstance();
startDateCal.setTime(startDate);
startDateCal.set(Calendar.HOUR, 0);
startDateCal.set(Calendar.MINUTE, 0);
startDateCal.set(Calendar.SECOND, 0);
startDateCal.set(Calendar.MILLISECOND, 0);
Calendar endDateCal = Calendar.getInstance();
endDateCal.setTime(endDate);
...
longdaysBetweenCalendars(Calendar date1, Calendar date2)
days Between Calendars
long d1 = getDaysFromYearZero(date1);
long d2 = getDaysFromYearZero(date2);
return d2 - d1;
IntegerdaysBetweenDate(Integer startDate, Integer endDate)
days Between Date
if (startDate == null || endDate == null) {
    return null;
Calendar c1 = newCalendar(startDate);
Calendar c2 = newCalendar(endDate);
Long lg = (c2.getTimeInMillis() - c1.getTimeInMillis()) / 1000 / 60 / 60 / 24;
return lg.intValue();
intdaysBetweenDates(Date beginDate, Date endDate)
days Between Dates
int days = 0;
Calendar calo = Calendar.getInstance();
Calendar caln = Calendar.getInstance();
calo.setTime(beginDate);
caln.setTime(endDate);
int oday = calo.get(6);
int nyear = caln.get(1);
for (int oyear = calo.get(1); nyear > oyear;) {
...
longdaysBetweenMidnight(final Date startDate, final Date endDate)
Berechnet die Tage zwischen zwei Tagen jeweils ab Mitternacht.
Calendar startCal = new GregorianCalendar();
startCal.setTime(startDate);
startCal.set(Calendar.HOUR_OF_DAY, 0);
startCal.set(Calendar.MINUTE, 0);
startCal.set(Calendar.SECOND, 0);
startCal.set(Calendar.MILLISECOND, 0);
Calendar endCal = new GregorianCalendar();
endCal.setTime(endDate);
...
longgetBetweenDate(Date startDate, Date endDate)
get Between Date
long startDateTime = startDate.getTime();
long endDateTime = endDate.getTime();
long dayTime = 24 * 60 * 60 * 1000;
long days = (endDateTime - startDateTime) / dayTime;
return days;
GregorianCalendar[]getBetweenDate(String d1, String d2)
get Between Date
Vector<GregorianCalendar> v = new Vector<GregorianCalendar>();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
GregorianCalendar gc1 = new GregorianCalendar(), gc2 = new GregorianCalendar();
try {
    gc1.setTime(sdf.parse(d1));
    gc2.setTime(sdf.parse(d2));
    do {
        GregorianCalendar gc3 = (GregorianCalendar) gc1.clone();
...
ListgetBetweenDateBuckets(Date from, Date to)
From/to inclusive
final List<Date> buckets = new ArrayList<>();
if (to.after(from)) {
    Calendar f = dateToCalendar(from);
    Calendar t = dateToCalendar(to);
    int gap = gapInDays(f, t);
    buckets.add(from);
    for (int i = 1; i <= gap; i++) {
        buckets.add(addDays(from, i));
...
ListgetBetweenDates(Date fromDate, Date toDate )
get Between Dates
ArrayList<Date> resultDates = new ArrayList<Date>();
Calendar calendar = Calendar.getInstance();
calendar.setTime(fromDate);
Date tmpDate = calendar.getTime();
long endTime = toDate.getTime();
while (tmpDate.before(toDate) || tmpDate.getTime() == endTime) {
    resultDates.add(calendar.getTime());
    calendar.add(Calendar.DAY_OF_YEAR, 1);
...
intgetBetweenDays(String strFromDate, String strToDate)
get Between Days
try {
    Calendar clFrom = new GregorianCalendar();
    int iYear = Integer.parseInt(strFromDate.substring(0, 4));
    int iMonth = Integer.parseInt(strFromDate.substring(4, 6));
    int iDay = Integer.parseInt(strFromDate.substring(6, 8));
    clFrom.set(iYear, iMonth, iDay, 0, 0, 0);
    Calendar clTo = new GregorianCalendar();
    iYear = Integer.parseInt(strToDate.substring(0, 4));
...