Java Utililty Methods Day End

List of utility methods to do Day End

Description

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

Method

intgetTotalMonths(final Date startDateToCheck, final Date endDateToCheck)
Number of month in between start and end date
int calculatedMonths = 0;
Calendar startDateToCheckC = Calendar.getInstance();
startDateToCheckC.setTime(startDateToCheck);
Calendar endDateToCheckC = Calendar.getInstance();
endDateToCheckC.setTime(endDateToCheck);
if (startDateToCheckC.get(Calendar.YEAR) != endDateToCheckC.get(Calendar.YEAR)) {
    int fullYears = endDateToCheckC.get(Calendar.YEAR) - startDateToCheckC.get(Calendar.YEAR) - 1;
    int startYearMonthCount = 12 - startDateToCheckC.get(Calendar.MONTH);
...
Date[][]getTrendTime(Date date)
get Trend Time
Date[][] dates = new Date[6][2];
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.set(Calendar.DAY_OF_MONTH, 0);
dates[5][1] = calendar.getTime();
calendar.set(Calendar.DAY_OF_MONTH, 1);
dates[5][0] = calendar.getTime();
calendar.set(Calendar.DAY_OF_MONTH, 0);
...
LonggetWorkingDays(Calendar start, Calendar end, final Long[] holidays)
get Working Days
Long result = 0L;
int startDayOfWeek = start.get(Calendar.DAY_OF_WEEK);
int endDayOfWeek = end.get(Calendar.DAY_OF_WEEK);
if (!isWorkingDay(start.getTime(), holidays)) {
    start = nextWorkingDay(start, holidays);
if (!isWorkingDay(end.getTime(), holidays)) {
    end = previousWorkingDay(end, holidays);
...
intgetWorkingDaysBetweenTwoDates(Date startDate, Date endDate)
Original code from source: http://stackoverflow.com/questions/4600034/calculate -number-of-weekdays-between-two-dates-in-java
startDate = setTime(startDate, 12, 0);
endDate = setTime(endDate, 12, 0);
Calendar startCal = Calendar.getInstance();
startCal.setTime(startDate);
Calendar endCal = Calendar.getInstance();
endCal.setTime(endDate);
int workDays = 0;
if (startCal.getTimeInMillis() == endCal.getTimeInMillis()) {
...
longgetYearsBetween(Date startDate, Date endDate)
get Years Between
long msBetween = getMsBetween(startDate, endDate);
return miliSecondsToYears(msBetween);
intgetYearsBetweenDate(Date begin, Date end)
get Years Between Date
int bYear = getDateField(begin, Calendar.YEAR);
int eYear = getDateField(end, Calendar.YEAR);
return eYear - bYear;
booleanisBetweenDate(Date date, Date startDate, Date endDate)
Not Consider time.
Date clonedDate = (Date) date.clone();
clonedDate = formatDateByTime(clonedDate, 0, 0, 0, 0);
Date clonedStartDate = (Date) startDate.clone();
Date clonedEndDate = (Date) endDate.clone();
clonedStartDate = formatDateByTime(clonedStartDate, 0, 0, 0, 0);
clonedEndDate = formatDateByTime(clonedEndDate, 23, 59, 59, 999);
return (clonedDate.equals(clonedStartDate) || clonedDate.after(clonedStartDate))
        && (clonedDate.equals(clonedEndDate) || clonedDate.before(clonedEndDate));
...
booleanisBetWeenDates(Date in, Date from, Date to)
is Bet Ween Dates
if (in != null) {
    return in.after(from) && in.before(to) || isEqualDate(in, from) || isEqualDate(in, to);
return false;
booleanisCalenderDaySame(GregorianCalendar aInCal1, GregorianCalendar aInCal2)
is Calender Day Same
if ((aInCal1 == null) && (aInCal2 != null)) {
    return false;
if ((aInCal2 == null) && (aInCal1 != null)) {
    return false;
if ((aInCal2 == null) && (aInCal1 == null)) {
    return true;
...
booleanisEndOfMonth(Date d)
is End Of Month
int date = d.getDate();
if (date < 28)
    return false;
int month = d.getMonth();
if (month == Calendar.FEBRUARY)
    return date >= 28;
if (month == Calendar.APRIL || month == Calendar.JUNE || month == Calendar.SEPTEMBER
        || month == Calendar.NOVEMBER)
...