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

DateresetDay(Date date)
reset Day
Date result = null;
if (date != null) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);
    calendar.set(Calendar.DAY_OF_MONTH, 1);
    calendar.set(Calendar.MONTH, 0);
    calendar.set(Calendar.YEAR, 1970);
    result = calendar.getTime();
...
java.util.CalendarresetHourMinSecMill(Date date)
reset Hour Min Sec Mill
java.util.Calendar calendar = java.util.Calendar.getInstance();
if (date != null) {
    calendar.setTime(date);
calendar.set(java.util.Calendar.MILLISECOND, 0);
calendar.set(java.util.Calendar.SECOND, 0);
calendar.set(java.util.Calendar.MINUTE, 0);
calendar.set(java.util.Calendar.HOUR_OF_DAY, 0);
...
DateresetTime(Date date)
set 00:00 for a date
Calendar cal = Calendar.getInstance();
return resetTime(date, cal);
DateresetTime(Date dt)
reset Time
Calendar cal = Calendar.getInstance();
cal.setTime(dt);
cal.set(Calendar.HOUR, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
cal.set(Calendar.AM_PM, Calendar.AM);
return cal.getTime();
...
DatesetDate(Date date, int year, int month, int day)
set Date
Calendar calendar = Calendar.getInstance();
if (date != null)
    calendar.setTime(date);
if (year > 0)
    calendar.set(Calendar.YEAR, year);
if (month >= 0)
    calendar.set(Calendar.MONTH, month);
if (day > 0)
...
DatesetDate(Date dateToSet, int hours, int minutes, int seconds, int milisec, TimeZone zone, Locale locale)
Returns a new Date object from the given Date object and sets the given parameters.
Calendar cal = Calendar.getInstance(zone, locale);
cal.setTime(dateToSet);
cal.set(Calendar.HOUR_OF_DAY, hours);
cal.set(Calendar.MINUTE, minutes);
cal.set(Calendar.SECOND, seconds);
cal.set(Calendar.MILLISECOND, milisec);
return cal.getTime();
DateSetDate(int year, int month, int day)
Set Date
Calendar c1 = Calendar.getInstance();
c1.set(year, month, day);
return c1.getTime();
CalendarsetDate(int year, int month, int day)
set Date
Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
calendar.setLenient(false);
calendar.set(Calendar.YEAR, year);
calendar.set(Calendar.MONTH, month);
calendar.set(Calendar.DAY_OF_MONTH, day);
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
...
DatesetDateHourMinute(Date dateParam, String hourMinute, String format)
set Date Hour Minute
String[] arrHourMinute = hourMinute.split(format);
Calendar dteComp = Calendar.getInstance();
dteComp.setTime(dateParam);
dteComp.set(Calendar.HOUR_OF_DAY, Integer.parseInt(arrHourMinute[0]));
dteComp.set(Calendar.MINUTE, Integer.parseInt(arrHourMinute[1]));
return dteComp.getTime();
DatesetDateSecond(Date dateParam, int second)
set Date Second
Calendar dteComp = Calendar.getInstance();
dteComp.setTime(dateParam);
dteComp.set(Calendar.SECOND, second);
return dteComp.getTime();