Android Utililty Methods Date Set

List of utility methods to do Date Set

Description

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

Method

Calendarceiling(Calendar date, int field)

Ceil this date, leaving the field specified as the most significant field.

For example, if you had the datetime of 28 Mar 2002 13:45:01.231, if you passed with HOUR, it would return 28 Mar 2002 13:00:00.000.

if (date == null) {
    throw new IllegalArgumentException("The date must not be null");
Calendar ceiled = (Calendar) date.clone();
modify(ceiled, field, MODIFY_CEILING);
return ceiled;
Dateceiling(Date date, int field)

Ceil this date, leaving the field specified as the most significant field.

For example, if you had the datetime of 28 Mar 2002 13:45:01.231, if you passed with HOUR, it would return 28 Mar 2002 14:00:00.000.

if (date == null) {
    throw new IllegalArgumentException("The date must not be null");
Calendar gval = Calendar.getInstance();
gval.setTime(date);
modify(gval, field, MODIFY_CEILING);
return gval.getTime();
Dateceiling(Object date, int field)

Ceil this date, leaving the field specified as the most significant field.

For example, if you had the datetime of 28 Mar 2002 13:45:01.231, if you passed with HOUR, it would return 28 Mar 2002 13:00:00.000.

if (date == null) {
    throw new IllegalArgumentException("The date must not be null");
if (date instanceof Date) {
    return ceiling((Date) date, field);
} else if (date instanceof Calendar) {
    return ceiling((Calendar) date, field).getTime();
} else {
...
DateoffsetDay(Date date, int offset)
offset Day
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.set(Calendar.DAY_OF_YEAR,
        (calendar.get(Calendar.DAY_OF_YEAR) + offset));
return calendar.getTime();
DateoffsetHour(Date date, int offset)
offset Hour
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.set(Calendar.HOUR_OF_DAY,
        (calendar.get(Calendar.HOUR_OF_DAY) + offset));
return calendar.getTime();
Dateset(Date date, int calendarField, int amount)
Sets the specified field to a date returning a new object.
if (date == null) {
    throw new IllegalArgumentException("The date must not be null");
Calendar c = Calendar.getInstance();
c.setLenient(false);
c.setTime(date);
c.set(calendarField, amount);
return c.getTime();
...
DatesetDays(Date date, int amount)
Sets the day of month field to a date returning a new object.
return set(date, Calendar.DAY_OF_MONTH, amount);
DatesetHour(Date date, int hours)
set Hour
return setTime(date, hours, -1, -1, -1);
DatesetHours(Date date, int amount)
Sets the hours field to a date returning a new object.
return set(date, Calendar.HOUR_OF_DAY, amount);
DatesetMilliseconds(Date date, int amount)
Sets the miliseconds field to a date returning a new object.
return set(date, Calendar.MILLISECOND, amount);