Java 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

DatesetYear(Date d, int year)
set Year
Calendar c = getCalendar();
c.setTime(d);
c.set(Calendar.YEAR, year);
return (c.getTime());
DatesetYear(Date date, int year)
set Year
return setField(date, Calendar.YEAR, year);
DatestripTime(Date d)
set the time portion of a Date to all 0's
Calendar cal = Calendar.getInstance();
cal.setTime(d);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
return cal.getTime();
DatestripTime(Date date)
Returns a Date object representing 00:00:00AM of the input date.
Calendar calendar = Calendar.getInstance();
calendar.clear();
Calendar copy = Calendar.getInstance();
copy.setTime(date);
calendar.set(Calendar.DATE, calendar.get(Calendar.DATE));
calendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH));
calendar.set(Calendar.YEAR, calendar.get(Calendar.YEAR));
return calendar.getTime();
...
DatestripTime(Date date)
Strips the time component from a date.
return addDays(date, 0, true);
DatestripTime(Date time)
strip Time
GregorianCalendar gc = new GregorianCalendar();
gc.setTime(time);
int month = gc.get(Calendar.MONTH) + 1;
int day = gc.get(Calendar.DAY_OF_MONTH);
int year = gc.get(Calendar.YEAR);
GregorianCalendar gc2 = new GregorianCalendar(year, month, day);
return gc2.getTime();
DatestripTimeFromDate(Date aDate)
Strips the time information from a given Date (sets all time fields to zero).
Calendar tempCalendar = Calendar.getInstance();
tempCalendar.setTime(aDate);
tempCalendar.set(Calendar.HOUR_OF_DAY, 0);
tempCalendar.set(Calendar.MINUTE, 0);
tempCalendar.set(Calendar.SECOND, 0);
tempCalendar.set(Calendar.MILLISECOND, 0);
return tempCalendar.getTime();