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

DatesetTime(final Date date, final int hourOfDay, final int minute, final int second, final int ms)
Set the time of the given Date
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);
gc.set(Calendar.MILLISECOND, ms);
return gc.getTime();
DatesetTime(final Date date, final int hours, final int minutes, final int seconds)
Given a Date as parameter, it sets it to the specified time and returns a copy.
final Calendar aux = Calendar.getInstance();
aux.setTime(date);
aux.set(Calendar.MILLISECOND, 0);
aux.set(Calendar.HOUR, hours);
aux.set(Calendar.MINUTE, minutes);
aux.set(Calendar.SECOND, seconds);
return aux.getTime();
DatesetTimeForDate(Date date, int h, int m, int s)
set Time For Date
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.set(Calendar.HOUR_OF_DAY, h);
cal.set(Calendar.MINUTE, m);
cal.set(Calendar.SECOND, s);
return cal.getTime();
DatesetTimePart(Date date, String time, Integer milliseconds)
Sets the time part of the given date by using pattern 'HHmmss', and sets the milliseconds.
if (time == null)
    return null;
if (time.length() != 6)
    return null;
int hour = Integer.parseInt(time.substring(0, 2));
int minute = Integer.parseInt(time.substring(2, 4));
int second = Integer.parseInt(time.substring(4, 6));
GregorianCalendar calendar = new GregorianCalendar();
...
DatesetTimeToNull(Date date)
Set the time of a given date to 00:00:00.00
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();
DatesetTimeToZero(final Date date)
set Time To Zero
final GregorianCalendar calendar = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
calendar.setTimeInMillis(date.getTime()); 
calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH),
        0, 0, 0);
calendar.set(Calendar.MILLISECOND, 0);
return calendar.getTime();
DatesetTimeZero(Date dt)
Set the time to zero 00:00:00
if (dt == null)
    return null;
GregorianCalendar gc = new GregorianCalendar();
gc.setTime(dt);
gc.set(Calendar.HOUR_OF_DAY, 0);
gc.set(Calendar.MINUTE, 0);
gc.set(Calendar.SECOND, 0);
gc.set(Calendar.MILLISECOND, 0);
...
DatesetToDayStartTime(Date date)
set To Day Start Time
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(date.getTime());
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
return calendar.getTime();
DatesetToLastDayInMonth(final Date date)
set To Last Day In Month
final Calendar aux = Calendar.getInstance();
aux.setTime(date);
aux.set(Calendar.DAY_OF_MONTH, aux.getActualMaximum(Calendar.DAY_OF_MONTH));
return aux.getTime();
DatesetToMidnight(Date d)
set a date to midnight
GregorianCalendar cal = new GregorianCalendar();
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();