Java Utililty Methods Calendar Time

List of utility methods to do Calendar Time

Description

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

Method

CalendargetTimeZoneCalendar(final TimeZone timeZone)
get Time Zone Calendar
return TIMEZONE_CALENDARS.get().computeIfAbsent(timeZone, GregorianCalendar::new);
StringgetTimezoneString(Calendar cal)
get Timezone String
int tzoffset = (cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET)) / 60000;
char tzsign = tzoffset > 0 ? '+' : '-';
tzoffset = Math.abs(tzoffset);
StringBuilder sb = new StringBuilder(5);
sb.append(tzsign);
append2DigitNumber(sb, tzoffset / 60);
append2DigitNumber(sb, tzoffset % 60);
return sb.toString();
...
booleanhasTime(Calendar cal)
Method to check whether hour, minute, second and millisecond fields are set
boolean hasTime = cal.isSet(Calendar.HOUR_OF_DAY) && cal.isSet(Calendar.MINUTE)
        && cal.isSet(Calendar.SECOND) && cal.isSet(Calendar.MILLISECOND);
return hasTime;
booleanhasTimePart(Calendar calendar)
Whether the calendar has time part
return calendar.get(Calendar.HOUR_OF_DAY) > 0 || calendar.get(Calendar.MINUTE) > 0
        || calendar.get(Calendar.SECOND) > 0;
booleanisEquals(Calendar startTime, Calendar timeCurrent, int type)
is Equals
if (startTime == null || timeCurrent == null) {
    return false;
if (startTime.get(Calendar.YEAR) == timeCurrent.get(Calendar.YEAR)) {
    if (type == Calendar.YEAR) {
        return true;
    if (startTime.get(Calendar.WEEK_OF_YEAR) == timeCurrent.get(Calendar.WEEK_OF_YEAR)) {
...
booleanisFirstMorning(Calendar time, Calendar previous)
Tests if this will be the first good morning trigger for a message.
if (time == null || previous == null) {
    return false;
if (time.get(Calendar.YEAR) == previous.get(Calendar.YEAR)
        && time.get(Calendar.DAY_OF_YEAR) == previous.get(Calendar.DAY_OF_YEAR)
        && previous.get(Calendar.HOUR_OF_DAY) >= 6) {
    return false;
return true;
booleanisFuture(Calendar time)
is Future
if (time != null) {
    Calendar cal = getCalendar();
    cal.add(Calendar.WEEK_OF_MONTH, 2);
    snapStartOfWorkWeek(cal);
    return time.compareTo(cal) > -1;
return false;
booleanisMorning(Calendar time)
Tests if a time is during the morning.
if (time == null) {
    return false;
int hour = time.get(Calendar.HOUR_OF_DAY);
return hour >= 6 && hour <= 10;
booleanisOverTime(Calendar lastTime, Calendar currentTime, Calendar begTime, Calendar endTime)
is Over Time
return isOverTime(lastTime.getTimeInMillis(), currentTime.getTimeInMillis(), begTime.getTimeInMillis(),
        endTime.getTimeInMillis());
booleanisSameLocalTime(Calendar cal1, Calendar cal2)
is Same Local Time
if ((cal1 == null) || (cal2 == null)) {
    throw new IllegalArgumentException("The date must not be null");
return (cal1.get(14) == cal2.get(14)) && (cal1.get(13) == cal2.get(13)) && (cal1.get(12) == cal2.get(12))
        && (cal1.get(10) == cal2.get(10)) && (cal1.get(6) == cal2.get(6)) && (cal1.get(1) == cal2.get(1))
        && (cal1.get(0) == cal2.get(0)) && (cal1.getClass() == cal2.getClass());