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

intgetMonths(Date end, Date start)
get Months
Calendar aCalendar = Calendar.getInstance();
Calendar bCalendar = Calendar.getInstance();
aCalendar.setTime(end);
bCalendar.setTime(start);
int months = 0;
while (aCalendar.before(bCalendar)) {
    months++;
    aCalendar.add(Calendar.MONTH, 1);
...
IntegergetMonthsBetweenBeginDateAndEndDate(Date beginDate, Date endDate)
get Months Between Begin Date And End Date
Calendar cal1 = Calendar.getInstance();
cal1.setTime(beginDate);
Calendar cal2 = Calendar.getInstance();
cal2.setTime(endDate);
int year = cal2.get(Calendar.YEAR) - cal1.get(Calendar.YEAR);
int month = cal2.get(Calendar.MONTH) - cal1.get(Calendar.MONTH);
month = year * 12 + month;
month += 1;
...
intgetMonthSpan(Date begin, Date end)
get Month Span
Calendar beginCal = new GregorianCalendar();
beginCal.setTime(begin);
Calendar endCal = new GregorianCalendar();
endCal.setTime(end);
int m = (endCal.get(Calendar.MONTH)) - (beginCal.get(Calendar.MONTH));
int y = (endCal.get(Calendar.YEAR)) - (beginCal.get(Calendar.YEAR));
return y * 12 + m;
intgetMonthSpan(Date start, Date end)
This method returns the number of months between the specified dates.
GregorianCalendar first = createCalendar(start);
GregorianCalendar last = createCalendar(end);
int monthSpan = 0;
first.set(DAY_OF_MONTH, 1);
monthSpan += (last.get(MONTH) - first.get(MONTH));
monthSpan += 12 * (last.get(YEAR) - first.get(YEAR));
if (monthSpan < 0) {
    monthSpan = 0;
...
longgetMsBetween(Date startDate, Date endDate)
get Ms Between
Calendar cal = getCalendar();
cal.setTime(startDate);
long startMs = cal.getTimeInMillis();
cal.setTime(endDate);
long endMs = cal.getTimeInMillis();
return endMs - startMs;
DategetNextEndDate(Date date, int offset)
get Next End Date
if (offset < 1) {
    return date;
} else {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);
    for (int dayOfWeek = calendar.get(7); offset > 0; --offset) {
        if (dayOfWeek == 6) {
            calendar.add(5, 3);
...
DategetNextSendTime(Date sendDate, Date start)
get Next Send Time
Calendar calendar = Calendar.getInstance();
if (sendDate != null) {
    calendar.setTime(sendDate);
Calendar startCalendar = Calendar.getInstance();
if (start == null) {
    startCalendar.set(Calendar.HOUR_OF_DAY, 8);
    startCalendar.set(Calendar.MINUTE, 0);
...
IntegergetNumberOfDaysBetweenDates(Date beginDate, Date endDate)
get Number Of Days Between Dates
Calendar c1 = Calendar.getInstance();
Calendar c2 = Calendar.getInstance();
c1.setTime(beginDate);
c2.setTime(endDate);
long timeBetweenInMillis = c2.getTimeInMillis() - c1.getTimeInMillis();
Integer numberDaysBetweenDates = new Integer(new Long(timeBetweenInMillis / (3600000 * 24)).intValue());
return numberDaysBetweenDates;
intgetNumberOfMonthsBetween(final Date begin, final Date end)
get Number Of Months Between
if (begin == null || end == null)
    return -1;
Calendar cal1 = Calendar.getInstance();
cal1.setTime(begin);
Calendar cal2 = Calendar.getInstance();
cal2.setTime(end);
return (cal2.get(Calendar.YEAR) - cal1.get(Calendar.YEAR)) * 12
        + (cal2.get(Calendar.MONTH) - cal1.get(Calendar.MONTH));
...
intgetNumMonths(Date dStart, Date dEnd)
Gets the number of months between two date objects
int i = 0;
Calendar calendar = Calendar.getInstance();
calendar.setTime(dStart);
while (calendar.getTime().before(dEnd) || calendar.getTime().equals(dEnd)) {
    calendar.add(Calendar.MONTH, 1);
    i++;
i--;
...