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

longgetMinllisBetween(Date beginDate, Date endDate)
get Minllis Between
Calendar d1 = new GregorianCalendar();
d1.setTime(beginDate);
Calendar d2 = new GregorianCalendar();
d2.setTime(endDate);
if (d1.after(d2)) {
    return 0;
long minllis = d2.getTimeInMillis() - d1.getTimeInMillis();
...
ListgetMondays(Date startDate, Date endDate)
get Mondays
if (endDate != null && !startDate.before(endDate)) {
    throw new RuntimeException("startDate must before endDate.");
List<Date> mondayList = new ArrayList<Date>();
Date previousMonday = getPreviousMonday(endDate);
for (; !previousMonday.before(startDate); previousMonday = getPreviousMonday(previousMonday)) {
    mondayList.add(previousMonday);
return mondayList;
IntegergetMonthBetween(Date startDate, Date endDate)
get Month Between
if (startDate == null || endDate == null || !startDate.before(endDate)) {
    return null;
Calendar start = Calendar.getInstance();
start.setTime(startDate);
Calendar end = Calendar.getInstance();
end.setTime(endDate);
int year1 = start.get(Calendar.YEAR);
...
intgetMonthCha(Date start, Date end)
get Month Cha
Calendar c1 = Calendar.getInstance();
Calendar c2 = Calendar.getInstance();
c1.setTime(start);
c2.setTime(end);
int y1 = c1.get(Calendar.YEAR);
int y2 = c2.get(Calendar.YEAR);
int m1 = c1.get(Calendar.MONTH);
int m2 = c2.get(Calendar.MONTH);
...
intgetMonthCount(Date startDate, Date endDate)
Return month count.
int count = 1;
Calendar calendar = Calendar.getInstance();
calendar.setTime(endDate);
count += calendar.get(Calendar.YEAR) * 12 + calendar.get(Calendar.MONTH);
calendar.setTime(startDate);
count -= calendar.get(Calendar.YEAR) * 12 + calendar.get(Calendar.MONTH);
return count;
DategetMonthEnd(Date date)
get Month End
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.MONTH, 1);
int index = calendar.get(Calendar.DAY_OF_MONTH);
calendar.add(Calendar.DATE, (-index));
return calendar.getTime();
DategetMonthEndDate(Date date)
get Month End Date
GregorianCalendar c = new GregorianCalendar();
c.setTime(date);
int maxMonth = c.getActualMaximum(Calendar.DAY_OF_MONTH);
c.set(Calendar.DAY_OF_MONTH, maxMonth);
c.set(Calendar.HOUR_OF_DAY, 23);
c.set(Calendar.MINUTE, 59);
c.set(Calendar.SECOND, 59);
return c.getTime();
...
DategetMonthEndDate(int year, int month)
get Month End Date
Calendar c = Calendar.getInstance();
c.set(Calendar.YEAR, year);
c.set(Calendar.MONTH, month);
c.set(Calendar.DAY_OF_MONTH, 0);
c.set(Calendar.HOUR_OF_DAY, 23);
c.set(Calendar.MINUTE, 59);
c.set(Calendar.SECOND, 59);
return c.getTime();
...
LonggetMonthEndDate(Long day)
get Month End Date
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(day);
int end = cal.getActualMaximum(Calendar.DATE);
cal.set(Calendar.DATE, end);
return cal.getTimeInMillis();
ListgetMonthFirstDays(Date startDate, Date endDate)
get Month First Days
if (endDate != null && !startDate.before(endDate)) {
    throw new RuntimeException("startDate must before endDate.");
List<Date> monthFirstDayList = new ArrayList<Date>();
Date previousMonthFirstDay = getPreviousMonthFirstDay(endDate);
for (; !previousMonthFirstDay
        .before(startDate); previousMonthFirstDay = getPreviousMonthFirstDay(previousMonthFirstDay)) {
    monthFirstDayList.add(previousMonthFirstDay);
...