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

DategetSatDayOfWeek(Date date)
get Sat Day Of Week
if (date == null) {
    return null;
Calendar c = new GregorianCalendar();
c.setFirstDayOfWeek(Calendar.MONDAY);
c.setTime(date);
c.set(Calendar.DAY_OF_WEEK, c.getFirstDayOfWeek() + 5);
return c.getTime();
...
CalendargetScheduledDate(int dayOfWeek, int hourOfDay, int minute, int second)
Converts input values to a Calendar
Calendar c = Calendar.getInstance();
int weekDay = c.get(Calendar.DAY_OF_WEEK);
int days = dayOfWeek - weekDay;
if (days < 0) {
    days += 7;
c.add(Calendar.DAY_OF_YEAR, days);
c.set(Calendar.HOUR_OF_DAY, hourOfDay);
...
StringgetSeqWeek(String date)
get Seq Week
int seqWeek = 0;
int curDate = getDate(date);
int[][] month = getMonthDays(date);
for (int i = 0; i < 6; i++) {
    for (int j = 0; j < 7; j++) {
        if (month[i][j] != 0) {
            if (month[i][j] == curDate)
                seqWeek = i + 1;
...
intgetSeqWeekByMonth(Date currDate)
get Seq Week By Month
Calendar c = Calendar.getInstance();
c.setTime(currDate);
c.setFirstDayOfWeek(Calendar.MONDAY);
return c.get(Calendar.WEEK_OF_MONTH);
DategetStartDate(int year, int week)
get Start Date
Calendar c = Calendar.getInstance(Locale.US);
c.set(year, 1, 1, 0, 0, 0);
c.set(Calendar.WEEK_OF_YEAR, week);
c.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
c.add(Calendar.DAY_OF_YEAR, 1);
return c.getTime();
ListgetStartDates(Date baseDate, int weekNum)

Description:Get start date of weeks specified by parameter weekNum beginning from the week

specified by parameter baseDate
List<Date> result = new ArrayList<Date>();
Calendar calendar = Calendar.getInstance();
calendar.setTime(baseDate);
result.add(new Date(baseDate.getTime()));
for (int i = 0; i < weekNum - 1; i++) {
    calendar.add(Calendar.DAY_OF_YEAR, 7);
    result.add(calendar.getTime());
return result;
java.util.DategetSundayDate(int week, int year)
Gets the sunday date.
Calendar cal = getFirstSundayDateInYear(year);
cal.add(Calendar.DAY_OF_YEAR, (week - 1) * 7);
return cal.getTime();
DategetSundayOfWeek(Date date)
get Sunday Of Week
Calendar sunday = getCalendar();
sunday.setTime(date);
sunday.setFirstDayOfWeek(FIRST_DAY_OF_WEEK);
sunday.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
return sunday.getTime();
DategetThisweekFirst(Date early)
get Thisweek First
Calendar c1 = Calendar.getInstance();
c1.setTime(early);
int week = c1.get(Calendar.DAY_OF_WEEK);
int firstw = -1 * (week - 1);
Date weekFirst = dayAdd(early, firstw);
return weekFirst;
intgetWeek(Date date)
get Week
return getCalendar(date).get(7);