Java Day End dateSpan(Date beginDate, Date endDate)

Here you can find the source of dateSpan(Date beginDate, Date endDate)

Description

date Span

License

Open Source License

Declaration

public static int[] dateSpan(Date beginDate, Date endDate) 

Method Source Code

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

import java.util.Calendar;
import java.util.Date;

public class Main {
    public static int[] dateSpan(Date beginDate, Date endDate) {
        Calendar b_cal = Calendar.getInstance();
        b_cal.setTime(beginDate);//from ww  w. j  a va  2  s.co  m
        Calendar e_cal = Calendar.getInstance();
        e_cal.setTime(endDate);
        int year = e_cal.get(Calendar.YEAR) - b_cal.get(Calendar.YEAR);
        int month = e_cal.get(Calendar.MONTH) - b_cal.get(Calendar.MONTH);
        if (month < 0 && year > 0) {
            year--;
            month += 12;
        }
        int day = e_cal.get(Calendar.DATE) - b_cal.get(Calendar.DATE);
        if (day < 0 && month > 0) {
            month--;
            day += 30;
        }
        int hour = e_cal.get(Calendar.HOUR) - b_cal.get(Calendar.HOUR);
        if (hour < 0 && day > 0) {
            day--;
            hour += 24;
        }
        int minute = e_cal.get(Calendar.MINUTE) - b_cal.get(Calendar.MINUTE);
        if (minute < 0 && hour > 0) {
            hour--;
            minute += 60;
        }
        int second = e_cal.get(Calendar.SECOND) - b_cal.get(Calendar.SECOND);
        if (second < 0 && minute > 0) {
            minute--;
            second += 60;
        }
        int[] ymdhms = new int[6];
        ymdhms[0] = year;
        ymdhms[1] = month;
        ymdhms[2] = day;
        ymdhms[3] = hour;
        ymdhms[4] = minute;
        ymdhms[5] = second;
        return ymdhms;
    }
}

Related

  1. checkTimeInRangeWithSkew(Date timeToCheck, Date startDate, Date endDate, int skewInMinutes)
  2. checkTimePeriod(final Date beginHour, final Date endHour, final Date hour)
  3. countDaysBetween(Date start, Date end)
  4. countMonths(java.util.Date startDate, java.util.Date endDate)
  5. dateBetweens(Date start, Date end)
  6. dayBetweenTwoDates(Date beginDate, Date endDate)
  7. dayEnd(Date dt)
  8. dayEnd(final Date date)
  9. daysOfTwoDate(Date beginDate, Date endDate)