Java Utililty Methods Date to Day

List of utility methods to do Date to Day

Description

The list of methods to do Date to Day are organized into topic(s).

Method

DategetDay(Date date)
get Day
long time = date.getTime();
return new Date(time - ((time + timezoneOffset) % 86400000L));
DategetDay(Date date, int day)
get Day
long currDateMills = date.getTime();
long extraMills = day * 3600 * 1000 * 24;
Calendar result = Calendar.getInstance();
result.setTimeInMillis(currDateMills + extraMills);
return result.getTime();
intgetDay(Date dateParam)
get Day
if (dateParam == null) {
    throw new IllegalArgumentException("The dateParam  must not be null");
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(dateParam.getTime());
return cal.get(Calendar.DAY_OF_WEEK);
intgetDay(java.util.Date date)
get Day
java.util.Calendar c = java.util.Calendar.getInstance();
c.setTime(date);
return c.get(java.util.Calendar.DAY_OF_MONTH);
intgetDay(String strDate)
get Day
Calendar cal = parseDateTime(strDate);
return cal.get(Calendar.DATE);
IntegergetDayBetween(Date startDate, Date endDate)
get Day Between
Calendar start = Calendar.getInstance();
start.setTime(startDate);
start.set(Calendar.HOUR_OF_DAY, 0);
start.set(Calendar.MINUTE, 0);
start.set(Calendar.SECOND, 0);
start.set(Calendar.MILLISECOND, 0);
Calendar end = Calendar.getInstance();
end.setTime(endDate);
...
intgetDayCount(java.util.Date _startDate, java.util.Date _endDate)
get Day Count
Calendar calendar = Calendar.getInstance();
calendar.setTime(_startDate);
int startDay = calendar.get(Calendar.DAY_OF_YEAR);
int startYear = calendar.get(Calendar.YEAR);
calendar.clear();
calendar.setTime(_endDate);
int endDay = calendar.get(Calendar.DAY_OF_YEAR);
int endYear = calendar.get(Calendar.YEAR);
...
DategetDayEnd(Date date)
get Day End
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
calendar.add(Calendar.DAY_OF_MONTH, 1);
calendar.add(Calendar.MILLISECOND, -1);
...
DategetDayEnd(Date date)
Calculates end of the day
Calendar end = new GregorianCalendar();
end.setTime(date);
end.set(Calendar.HOUR_OF_DAY, 23);
end.set(Calendar.MINUTE, 59);
end.set(Calendar.SECOND, 59);
return end.getTime();
CalendargetDayEnd(Date date)
Gets a date which is at the end of a day.
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.set(Calendar.HOUR_OF_DAY, 23);
cal.set(Calendar.MINUTE, 59);
cal.set(Calendar.SECOND, 59);
cal.set(Calendar.MILLISECOND, 999);
return cal;