List of utility methods to do Calendar Time
boolean | isSameLocalTime(Calendar cal1, Calendar cal2) Checks if two calendar objects represent the same local time. This method compares the values of the fields of the two objects. if (cal1 == null || cal2 == null) { throw new IllegalArgumentException("The date must not be null"); return (cal1.get(Calendar.MILLISECOND) == cal2.get(Calendar.MILLISECOND) && cal1.get(Calendar.SECOND) == cal2.get(Calendar.SECOND) && cal1.get(Calendar.MINUTE) == cal2.get(Calendar.MINUTE) && cal1.get(Calendar.HOUR) == cal2.get(Calendar.HOUR) && cal1.get(Calendar.DAY_OF_YEAR) == cal2.get(Calendar.DAY_OF_YEAR) ... |
boolean | isSameTime(final Calendar aCal1, final Calendar aCal2) is Same Time boolean retVal = aCal1.get(Calendar.HOUR_OF_DAY) == aCal2.get(Calendar.HOUR_OF_DAY); retVal = retVal && (aCal1.get(Calendar.MINUTE) == aCal2.get(Calendar.MINUTE)); retVal = retVal && (aCal1.get(Calendar.SECOND) == aCal2.get(Calendar.SECOND)); return retVal; |
boolean | isSleepTime(Calendar calendar, String sleepTimeStart, String sleepTimeEnd) is Sleep Time int sleepStart = Integer.parseInt(sleepTimeStart); int sleepEnd = Integer.parseInt(sleepTimeEnd); int hourofday = calendar.get(Calendar.HOUR_OF_DAY); return hourofday >= sleepStart || hourofday <= sleepEnd; |
boolean | isTime0(final Calendar calendar) is Time if (calendar.get(Calendar.HOUR_OF_DAY) == 0 && calendar.get(Calendar.MINUTE) == 0 && calendar.get(Calendar.SECOND) == 0 && calendar.get(Calendar.MILLISECOND) == 0) { return true; return false; |
boolean | isWorkTime(Calendar calendar, String workTimeStart, String workTimeEnd) is Work Time int dayofweek = calendar.get(Calendar.DAY_OF_WEEK); int hourofday = calendar.get(Calendar.HOUR_OF_DAY); int workStart = Integer.parseInt(workTimeStart); int workEnd = Integer.parseInt(workTimeEnd); return dayofweek > Calendar.SUNDAY && dayofweek < Calendar.SATURDAY && hourofday >= workStart && hourofday <= workEnd; |
void | maximizeTimeFields(final Calendar calendar) maximize Time Fields calendar.set(Calendar.HOUR_OF_DAY, 23); calendar.set(Calendar.MINUTE, 59); calendar.set(Calendar.SECOND, 59); calendar.set(Calendar.MILLISECOND, 999); |
Calendar | merge(Calendar date, Calendar time) Merge two calendars, one with the day date component and the other with a time component. Calendar resCal = Calendar.getInstance(); if (date == null && time == null) return resCal; if (date != null) resCal = (Calendar) date.clone(); resCal.clear(); if (null == time) { resCal.set(date.get(Calendar.YEAR), date.get(Calendar.MONTH), date.get(Calendar.DAY_OF_MONTH)); ... |
Calendar | mergeDateAndTime(final Calendar date, final Calendar time) merge Date And Time time.set(Calendar.YEAR, date.get(Calendar.YEAR));
time.set(Calendar.DAY_OF_MONTH, date.get(Calendar.DAY_OF_MONTH));
time.set(Calendar.MONTH, date.get(Calendar.MONTH));
return time;
|
Calendar | mergeDateTime(Calendar date, Calendar time) merge Date Time Calendar clendar = null;
if (date != null && time != null) {
clendar = Calendar.getInstance();
clendar.set(Calendar.YEAR, date.get(Calendar.YEAR));
clendar.set(Calendar.MONTH, date.get(Calendar.MONTH));
clendar.set(Calendar.DAY_OF_MONTH, date.get(Calendar.DAY_OF_MONTH));
clendar.set(Calendar.HOUR_OF_DAY, time.get(Calendar.HOUR_OF_DAY));
clendar.set(Calendar.MINUTE, time.get(Calendar.MINUTE));
...
|
Calendar | newCalendar(final long time) new Calendar final Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(time); return calendar; |