List of utility methods to do Date Set
Calendar | ceiling(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; |
Date | ceiling(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(); |
Date | ceiling(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 { ... |
Date | offsetDay(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();
|
Date | offsetHour(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();
|
Date | set(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(); ... |
Date | setDays(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);
|
Date | setHour(Date date, int hours) set Hour return setTime(date, hours, -1, -1, -1);
|
Date | setHours(Date date, int amount) Sets the hours field to a date returning a new object. return set(date, Calendar.HOUR_OF_DAY, amount);
|
Date | setMilliseconds(Date date, int amount) Sets the miliseconds field to a date returning a new object. return set(date, Calendar.MILLISECOND, amount);
|