Java Utililty Methods Calendar Day

List of utility methods to do Calendar Day

Description

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

Method

booleanisSameDay(final Calendar date1, final Calendar date2)
is Same Day
return getDaysBetween(date1, date2) < miliPerDay;
booleanisSunday(GregorianCalendar date)
is Sunday
return date.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY;
booleanisTheSameDay(Calendar dayOne, Calendar dayTwo)
Check if the calendars are referring to the same day
boolean result = false;
if (dayOne == null || dayTwo == null) {
    result = false;
} else {
    result = (dayTwo.get(Calendar.DAY_OF_YEAR) == dayOne.get(Calendar.DAY_OF_YEAR))
            && (dayTwo.get(Calendar.YEAR) == dayOne.get(Calendar.YEAR));
return result;
...
booleanisToday(Calendar creationDate)
is Today
Calendar today = Calendar.getInstance();
if (today.DAY_OF_MONTH == creationDate.DAY_OF_MONTH) {
    if (today.MONTH == creationDate.MONTH) {
        if (today.YEAR == creationDate.YEAR) {
            return true;
return false;
booleanisToday(Calendar date)
is Today
Calendar now = Calendar.getInstance();
if (date.get(Calendar.DAY_OF_YEAR) != now.get(Calendar.DAY_OF_YEAR))
    return false;
return date.get(Calendar.YEAR) == now.get(Calendar.YEAR);
booleanisToday(Calendar now, Calendar then)
Returns true if the given time is today
return now.get(Calendar.DAY_OF_MONTH) == then.get(Calendar.DAY_OF_MONTH)
        && now.get(Calendar.MONTH) == then.get(Calendar.MONTH)
        && now.get(Calendar.YEAR) == then.get(Calendar.YEAR);
BooleanisTodayOff(String days, Calendar calendar)
This method is used to check whether the day passed as parameter is an off day.
Boolean isOff = false;
Integer today = 0;
today = calendar.get(Calendar.DAY_OF_WEEK); 
switch (today) {
case Calendar.SUNDAY:
    if (days.contains("SU")) {
        isOff = true;
    break;
case Calendar.MONDAY:
    if (days.contains("MO")) {
        isOff = true;
    break;
case Calendar.TUESDAY:
    if (days.contains("TU")) {
        isOff = true;
    break;
case Calendar.WEDNESDAY:
    if (days.contains("WE")) {
        isOff = true;
    break;
case Calendar.THURSDAY:
    if (days.contains("TH")) {
        isOff = true;
    break;
case Calendar.FRIDAY:
    if (days.contains("FR")) {
        isOff = true;
    break;
case Calendar.SATURDAY:
    if (days.contains("SA")) {
        isOff = true;
    break;
default:
return isOff;
booleanisWithinDaysFuture(Calendar cal, int days)

Checks if a calendar date is after today and within a number of days in the future.

if (cal == null) {
    throw new IllegalArgumentException("The date must not be null");
Calendar today = Calendar.getInstance();
Calendar future = Calendar.getInstance();
future.add(Calendar.DAY_OF_YEAR, days);
return (isAfterDay(cal, today) && !isAfterDay(cal, future));
intjulianDay(Calendar calendar)
Calculates the julian day of a Calendar .
int year = calendar.get(Calendar.YEAR);
int month = calendar.get(Calendar.MONTH);
int day = calendar.get(Calendar.DAY_OF_MONTH);
return julianDay(year, month + 1, day);
IntegerminOfDay(Calendar calendar)
Return the calendars minute count since midnight
return calendar.get(Calendar.HOUR_OF_DAY * 60 + Calendar.MINUTE);