Java Day of Week 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.Calendar;
import java.util.Date;

public class Main {

    public static int weekCount(Date start, Date end) {
        final Calendar startCalendar = Calendar.getInstance();
        startCalendar.setTime(start);/*  w  w w  .  ja  va2 s. c  o m*/
        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. previousWeek(long date)
  2. startOfWeek(Date date)
  3. toStartWeek(Date date)
  4. toWeekDayUS(Date date, int expect)
  5. truncDateToIsoWeek(Date d)
  6. weekDay(final Date date)
  7. weekDaysBetween(final Date a, final Date b)
  8. WeekOfTheYear(Date dt)
  9. weekOfYear(Date date)