Java Week Calculate isSameWeekDates(Date date1, Date date2)

Here you can find the source of isSameWeekDates(Date date1, Date date2)

Description

is Same Week Dates

License

Apache License

Declaration

public static boolean isSameWeekDates(Date date1, Date date2) 

Method Source Code

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

import java.util.*;

public class Main {

    public static boolean isSameWeekDates(Date date1, Date date2) {
        Calendar cal1 = Calendar.getInstance();
        Calendar cal2 = Calendar.getInstance();
        cal1.setTime(date1);//from   w w  w. j a  v a2  s  .c om
        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;
        } else if (1 == subYear && 11 == cal2.get(Calendar.MONTH)) {
            if (cal1.get(Calendar.WEEK_OF_YEAR) == cal2.get(Calendar.WEEK_OF_YEAR))
                return true;
        } else if (-1 == subYear && 11 == cal1.get(Calendar.MONTH)) {
            if (cal1.get(Calendar.WEEK_OF_YEAR) == cal2.get(Calendar.WEEK_OF_YEAR))
                return true;
        }
        return false;
    }
}

Related

  1. getWeekNumberFromDate(Date date)
  2. getWeekOfDate(Date date)
  3. getWeekOfYear(Date date, Locale locale)
  4. getWeeksAddCount(int repType, int repIndex)
  5. getWeeksInYear(int year)
  6. nextWeek(Date date, int week)
  7. nextWeek(long date)
  8. plusHour(Date date, int plusWeek)
  9. startOfWeek(Date datum)