Java Utililty Methods Week Calculate

List of utility methods to do Week Calculate

Description

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

Method

intgetWeekOfDate(Date date)
get Week Of Date
Calendar c = Calendar.getInstance();
c.setTime(date);
return c.get(Calendar.DAY_OF_WEEK);
intgetWeekOfYear(Date date, Locale locale)
get Week Of Year
Calendar c = new GregorianCalendar(locale);
c.setTime(date);
return c.get(Calendar.WEEK_OF_YEAR);
intgetWeeksAddCount(int repType, int repIndex)
Gets count of weeks to add, when repetition was chosen.
int weekNum = new GregorianCalendar().get(Calendar.WEEK_OF_YEAR);
int add = 0;
if (repType == 0)
    add = 1;
if ((repType == 1 && weekNum % 2 == 1) || (repType == 2 && weekNum % 2 == 0)) {
    add = 2;
if ((repType == 1 && weekNum % 2 == 0) || (repType == 2 && weekNum % 2 == 1)) {
...
intgetWeeksInYear(int year)
get Weeks In Year
Calendar c = new GregorianCalendar();
c.set(year, 11, 31);
return c.get(Calendar.WEEK_OF_YEAR) == 53 ? 53 : 52;
booleanisSameWeekDates(Date date1, Date date2)
is Same Week Dates
Calendar cal1 = Calendar.getInstance();
Calendar cal2 = Calendar.getInstance();
cal1.setTime(date1);
cal2.setTime(date2);
int subYear = cal1.get(Calendar.YEAR) - cal2.get(Calendar.YEAR);
if (0 == subYear) {
    if (cal1.get(Calendar.WEEK_OF_YEAR) == cal2.get(Calendar.WEEK_OF_YEAR))
        return true;
...
DatenextWeek(Date date, int week)
next Week
Calendar cal = Calendar.getInstance();
if (date != null) {
    cal.setTime(date);
cal.add(Calendar.WEEK_OF_MONTH, week);
return cal.getTime();
longnextWeek(long date)
Returns the week after date.
return addDays(date, 7);
DateplusHour(Date date, int plusWeek)
plus Hour
return plusInteger(date, Calendar.HOUR, plusWeek);
DatestartOfWeek(Date datum)
start Of Week
if (datum == null) {
    return null;
Calendar c = new GregorianCalendar();
c.setTime(datum);
while (c.get(Calendar.DAY_OF_WEEK) != Calendar.MONDAY) {
    c.setTime(addDays(c.getTime(), -1));
return startOfDay(c.getTime());
GregorianCalendarweekCal(int weekNumber)
week Cal
int yearNum = INITIAL_YEAR + (weekNumber / 52);
int weekNum = weekNumber % 52;
GregorianCalendar cal = new GregorianCalendar();
cal.set(Calendar.YEAR, yearNum);
cal.set(Calendar.WEEK_OF_YEAR, weekNum);
return weekStart(cal);