Java Day of Week weeksBetween(Date date1, Date date2)

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

Description

weeks Between

License

Apache License

Declaration

public static int weeksBetween(Date date1, Date date2) 

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 weeksBetween(Date date1, Date date2) {
        int days = daysBetween(date1, date2);
        return (days % 7) == 0 ? (days / 7) : (days / 7) + 1;
    }/*w w w .j  a  va  2  s .  c  om*/

    public static int daysBetween(Date date1, Date date2) {
        if (date1 == null || date2 == null) {
            return 0;
        }
        Calendar cal = Calendar.getInstance();
        cal.setTime(date1);
        long time1 = cal.getTimeInMillis();
        cal.setTime(date2);
        long time2 = cal.getTimeInMillis();
        long between_days = (time2 - time1) / (1000 * 3600 * 24);
        return Integer.parseInt(String.valueOf(between_days));
    }
}

Related

  1. weekCount(Date start, Date end)
  2. weekDay(final Date date)
  3. weekDaysBetween(final Date a, final Date b)
  4. WeekOfTheYear(Date dt)
  5. weekOfYear(Date date)
  6. weeksBetween(Date early, Date late)
  7. weekStart(Date date)
  8. weekStart(Date date)