Java Calendar Week getADayOfWeek(Calendar day, int dayOfWeek)

Here you can find the source of getADayOfWeek(Calendar day, int dayOfWeek)

Description

get A Day Of Week

License

Apache License

Declaration

private static Calendar getADayOfWeek(Calendar day, int dayOfWeek) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.Calendar;

public class Main {
    private static Calendar getADayOfWeek(Calendar day, int dayOfWeek) {
        int week = day.get(Calendar.DAY_OF_WEEK);
        if (week == dayOfWeek)
            return day;
        int diffDay = dayOfWeek - week;
        if (week == Calendar.SUNDAY) {
            diffDay -= 7;/*from   w  w  w . j  a  v  a 2 s. c  o  m*/
        } else if (dayOfWeek == Calendar.SUNDAY) {
            diffDay += 7;
        }
        day.add(Calendar.DATE, diffDay);
        return day;
    }
}

Related

  1. convertIntToCalendarDayOfWeek(int dayOfWeek)
  2. endOfWeek(Calendar calendar, Date date)
  3. firstDayOfLastWeek(Calendar c)
  4. getDateOfLastDayOfWeekInMonth(Calendar calendar, int dayOfWeek)
  5. getDayFromPreviousWeek(Calendar requestDate)
  6. getDayOfWeek(Calendar c)
  7. getDayOfWeek(Calendar cal)