List of utility methods to do Calendar Day
int | date2day(Calendar cal) dateday return cal.get(Calendar.YEAR) * 10000 + (cal.get(Calendar.MONTH) + 1) * 100
+ cal.get(Calendar.DAY_OF_MONTH);
|
int | day(Calendar calendar) day return calendar.get(Calendar.DAY_OF_MONTH);
|
int | day(Calendar date) day return date.get(Calendar.DAY_OF_MONTH);
|
Calendar | day2date(int day, Calendar cal) daydate cal.clear();
cal.set(Calendar.YEAR, day / 10000);
cal.set(Calendar.MONTH, (day % 10000) / 100 - 1);
cal.set(Calendar.DAY_OF_MONTH, day % 100);
return cal;
|
Calendar | dayBegin(Calendar cal) Truncates time to zero, keeps date. cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
return cal;
|
void | dayBegin(Calendar calendar) day Begin calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); |
int | dayDistance(Calendar date1, Calendar date2) day Distance int noDays = 0; if (date1.before(date2)) { Calendar temp = Calendar.getInstance(); temp.setTimeInMillis(date1.getTimeInMillis()); while (temp.before(date2)) { temp.add(Calendar.DATE, 1); noDays++; } else if (date1.after(date2)) { Calendar temp = Calendar.getInstance(); temp.setTimeInMillis(date2.getTimeInMillis()); while (temp.before(date1)) { temp.add(Calendar.DATE, 1); noDays++; return noDays; |
Calendar | dayEndTime(Calendar calendar) Changes input calendar by resetting time fields to the end of day. calendar.set(Calendar.HOUR, calendar.getMaximum(Calendar.HOUR));
calendar.set(Calendar.MINUTE, calendar.getMaximum(Calendar.MINUTE));
calendar.set(Calendar.SECOND, calendar.getMaximum(Calendar.SECOND));
calendar.set(Calendar.MILLISECOND, calendar.getMaximum(Calendar.MILLISECOND));
return calendar;
|
void | dayFloor(Calendar calendar) day Floor hourFloor(calendar); calendar.set(Calendar.HOUR_OF_DAY, 0); |
Iterable | dayIterable(Calendar from, Calendar to) returns an interable of canonical days in (inclusive) range of days final Calendar nextDay = getCanonicalDay(from); final Calendar upto = getCanonicalDay(to); return new Iterable<Calendar>() { public Iterator<Calendar> iterator() { return new Iterator<Calendar>() { public boolean hasNext() { return !nextDay.after(upto); public Calendar next() { Calendar ret = getCanonicalDay(nextDay); nextDay.add(Calendar.DAY_OF_YEAR, 1); return ret; public void remove() { }; }; |