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

DatesetMinSeconds(Date date)
set Min Seconds
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.set(Calendar.SECOND, 0);
return cal.getTime();
DatesetMinute(Date date, int minute)
 Set minute of date object. 
if (date == null) {
    return null;
Calendar c = getCalendar(date);
c.set(Calendar.MINUTE, minute);
return c.getTime();
DatesetMinutes(Date date, int amount)
Sets the minute field to a date returning a new object.
return set(date, Calendar.MINUTE, amount);
DatesetStartDateIfNull(java.util.Date start)
set Start Date If Null
Date result = start;
if (start == null) {
    Calendar calendar = Calendar.getInstance();
    calendar.set(2013, Calendar.FEBRUARY, 1);
    result = calendar.getTime();
return result;
DatesetStartDay(Date date)
set Start Day
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.set(Calendar.HOUR_OF_DAY, 00);
calendar.set(Calendar.MINUTE, 00);
calendar.set(Calendar.SECOND, 00);
return calendar.getTime();
DatesetStartTime(Date date)
set Start Time
Calendar cal = Calendar.getInstance();
cal.setTime(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.getTime();
DatesetTime(Date date, int hourOfDay, int minute, int second)
set Time
Calendar calendar = newCalendar(date);
calendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
calendar.set(Calendar.MINUTE, minute);
calendar.set(Calendar.SECOND, second);
return calendar.getTime();
DatesetTime(Date date, int hours, int minutes, int seconds, int millis)
set Time
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.set(Calendar.HOUR_OF_DAY, hours);
calendar.set(Calendar.MINUTE, minutes);
calendar.set(Calendar.SECOND, seconds);
calendar.set(Calendar.MILLISECOND, millis);
return calendar.getTime();
DatesetTime(Date date, String timeString)
set Time
Calendar cal1 = Calendar.getInstance();
cal1.setTime(date);
Calendar cal2 = Calendar.getInstance();
String[] time = timeString.split(":");
cal2.set(cal1.get(Calendar.YEAR), cal1.get(Calendar.MONTH), cal1.get(Calendar.DAY_OF_MONTH),
        Integer.parseInt(time[0]), Integer.parseInt(time[1]), Integer.parseInt(time[2]));
return cal2.getTime();
DatesetTime(final Date date, final int hourOfDay, final int minute, final int second)
set Time
final GregorianCalendar gc = new GregorianCalendar();
gc.setTime(date);
gc.set(Calendar.HOUR_OF_DAY, hourOfDay);
gc.set(Calendar.MINUTE, minute);
gc.set(Calendar.SECOND, second);
return gc.getTime();