Android Utililty Methods Calendar Set

List of utility methods to do Calendar Set

Description

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

Method

voidsetTo2359(Calendar c)
set To
c.set(Calendar.HOUR_OF_DAY, 23);
c.set(Calendar.MINUTE, 59);
c.set(Calendar.SECOND, 59);
c.set(Calendar.MILLISECOND, 999);
voidsetToDec31(Calendar c)
set To Dec
c.set(Calendar.MONTH, 11);
c.set(Calendar.DAY_OF_MONTH, 31);
setTo2359(c);
voidmodify(Calendar val, int field, boolean round)
modify
if (val.get(Calendar.YEAR) > 280000000) {
    throw new ArithmeticException(
            "Calendar value too large for accurate calculations");
if (field == Calendar.MILLISECOND) {
    return;
Date date = val.getTime();
...
CalendarprepareCalendar(int hourOfDay, int minute)
prepare Calendar
Calendar calNow = Calendar.getInstance();
Calendar calSet = (Calendar) calNow.clone();
calSet.set(Calendar.HOUR_OF_DAY, hourOfDay);
calSet.set(Calendar.MINUTE, minute);
calSet.set(Calendar.SECOND, 0);
calSet.set(Calendar.MILLISECOND, 0);
if (calSet.compareTo(calNow) <= 0) {
    calSet.add(Calendar.DATE, 1);
...
DateTimetoDateTime(Calendar calendar)
to Date Time
DateTime dateTime = new DateTime();
dateTime.set(calendar.get(Calendar.MINUTE),
        calendar.get(Calendar.HOUR_OF_DAY),
        calendar.get(Calendar.DAY_OF_MONTH),
        calendar.get(Calendar.MONTH) + 1,
        calendar.get(Calendar.YEAR));
return dateTime;
voidstripTime(Calendar cal)
strip Time
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
voidsetDate(Calendar cal, long date)
set Date
int year = (int) (date / 10000);
int month = (int) ((date / 100) % 100);
int day = (int) (date % 100);
cal.set(year, month - 1, day);
voidsetTime(Calendar cal, long time)
set Time
int hour = (int) (time / 10000);
int minute = (int) ((time / 100) % 100);
int second = (int) (time % 100);
cal.set(Calendar.HOUR_OF_DAY, hour);
cal.set(Calendar.MINUTE, minute);
cal.set(Calendar.SECOND, second);
DatemoveToDate(int field, int amount)
move To Date
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date());
calendar.add(field, amount);
return calendar.getTime();