Java Week Calculate weekCount(Date start, Date end)

Here you can find the source of weekCount(Date start, Date end)

Description

week Count

License

Apache License

Declaration

public static int weekCount(Date start, Date end) 

Method Source Code

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

import java.util.*;

public class Main {

    public static int weekCount(Date start, Date end) {
        final Calendar startCalendar = Calendar.getInstance();
        startCalendar.setTime(start);/*from  ww  w  . ja  va 2  s .c  om*/
        final Calendar endCalendar = Calendar.getInstance();
        endCalendar.setTime(end);

        final int startWeekofYear = startCalendar.get(Calendar.WEEK_OF_YEAR);
        final int endWeekofYear = endCalendar.get(Calendar.WEEK_OF_YEAR);

        int count = endWeekofYear - startWeekofYear + 1;

        if (Calendar.SUNDAY != startCalendar.get(Calendar.DAY_OF_WEEK)) {
            count--;
        }

        return count;
    }
}

Related

  1. nextWeek(Date date, int week)
  2. nextWeek(long date)
  3. plusHour(Date date, int plusWeek)
  4. startOfWeek(Date datum)
  5. weekCal(int weekNumber)
  6. weekNumber()
  7. weeksInYear(int year)
  8. weekStart()