Java Day of Week getWeeksBetweenDate(Date begin, Date end)

Here you can find the source of getWeeksBetweenDate(Date begin, Date end)

Description

get Weeks Between Date

License

Apache License

Declaration

public static int getWeeksBetweenDate(Date begin, 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 getWeeksBetweenDate(Date begin, Date end) {
        int bWeek = getDateField(begin, Calendar.WEEK_OF_YEAR);
        int eWeek = getDateField(end, Calendar.WEEK_OF_YEAR);
        return eWeek - bWeek;
    }//from   w  w  w.  jav  a2  s  .c om

    private static int getDateField(Date date, int field) {
        Calendar c = getCalendar();
        c.setTime(date);
        return c.get(field);
    }

    private static Calendar getCalendar() {
        return Calendar.getInstance();
    }

    public static int get(int field, Date date) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        return c.get(field);
    }
}

Related

  1. getWeekOfYear(Date d, Locale locale)
  2. getWeekOfYear(Date date)
  3. getWeekOfYear(Date date)
  4. getWeekOfYear(Date date)
  5. getWeekOfYear(String date)
  6. getWeekStart(Date date)
  7. getWeekStart(Date date)
  8. getWeekStartDateBeforeCurrent(int weekNum, Date current)
  9. getWeekth(String sDate)