Java Utililty Methods Day of Week

List of utility methods to do Day of Week

Description

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

Method

DategetLastDayFromLastWeek(Date d)
Get last date from last week
Calendar cal = Calendar.getInstance();
cal.setTime(d);
if (cal.getFirstDayOfWeek() == Calendar.MONDAY) {
    cal.add(Calendar.WEEK_OF_YEAR, -1);
cal.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
cal.set(Calendar.HOUR_OF_DAY, 23);
cal.set(Calendar.MINUTE, 59);
...
DategetLastDayOfTheWeek(Date date)
get Last Day Of The Week
Calendar calendar = Calendar.getInstance(Locale.CHINA);
calendar.setTimeInMillis(date.getTime());
calendar.set(Calendar.DAY_OF_WEEK, 7);
calendar.set(Calendar.HOUR_OF_DAY, HOURS_OF_DAY);
calendar.set(Calendar.MINUTE, 59);
calendar.set(Calendar.SECOND, 59);
return new Date(calendar.getTimeInMillis());
DategetLastDayOfWeek(Date date)
get Last Day Of Week
Calendar c = new GregorianCalendar();
c.setFirstDayOfWeek(Calendar.SUNDAY);
c.setTime(date);
c.set(Calendar.DAY_OF_WEEK, c.getFirstDayOfWeek() + 6); 
return c.getTime();
DategetLastDayOfWeek(Date date)
get Last Day Of Week
Calendar calendar = Calendar.getInstance();
calendar.setFirstDayOfWeek(Calendar.SUNDAY);
calendar.setTime(date);
calendar.set(Calendar.DAY_OF_WEEK, calendar.getFirstDayOfWeek() + 6); 
return calendar.getTime();
DategetLastDayOfWeek(Date date)
get Last Day Of Week
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
if (calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
    calendar.add(Calendar.DAY_OF_YEAR, -1);
calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
calendar.set(Calendar.HOUR_OF_DAY, 23);
calendar.set(Calendar.MINUTE, 59);
...
DategetLastDayOfWeek(Date date)
get Last Day Of Week
Calendar c = new GregorianCalendar();
c.setFirstDayOfWeek(Calendar.MONDAY);
c.setTime(date);
c.set(Calendar.DAY_OF_WEEK, c.getFirstDayOfWeek() + 6); 
return c.getTime();
DategetLastDayOfWeek(Date date)
get Last Day Of Week
Calendar c = new GregorianCalendar();
c.setFirstDayOfWeek(Calendar.MONDAY);
c.setTime(date);
c.set(Calendar.DAY_OF_WEEK, c.getFirstDayOfWeek() + 6);
return c.getTime();
StringgetLastDayOfWeek(String str, int week)
get Last Day Of Week
String conStr = null;
int dayOfWeek = 0;
if (week == 0) {
    conStr = str;
    dayOfWeek = getCalendar(conStr).get(Calendar.DAY_OF_WEEK);
} else {
    conStr = addDays(str, week * 7);
    dayOfWeek = getCalendar(conStr).get(Calendar.DAY_OF_WEEK);
...
StringgetLastDayWeek(String s)
get Last Day Week
int minuscnt = whichDay(s);
minuscnt = minuscnt == 1 ? 0 : 7 - minuscnt + 1;
return addDays(s, minuscnt);
DategetLastMondayOfWeek(Date date)
get Last Monday Of Week
Date thismonday = getMondayOfWeek(date);
Calendar monday = getCalendar();
monday.setTime(thismonday);
monday.add(Calendar.DAY_OF_YEAR, -7);
return monday.getTime();