Java Week Calculate diffWeeks(Date start, Date end)

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

Description

Number of weeks difference between two dates

License

Apache License

Return

difference in weeks

Declaration

public static int diffWeeks(Date start, Date end) 

Method Source Code

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

import java.util.*;

public class Main {
    /**// ww w .  ja v  a 2s. c  om
     * Number of weeks difference between two dates
     *
     * @return difference in weeks
     */
    public static int diffWeeks(Date start, Date end) {
        if (start == null || end == null) {
            return -1;
        }
        return (int) ((end.getTime() - start.getTime()) / (1000 * 60 * 60 * 24 * 7) + 1);
    }

    /**
     * Number of weeks difference between two dates
     *
     * @return difference in weeks
     */
    public static int diffWeeks(Calendar start, Calendar end) {
        return diffWeeks(start.getTime(), end.getTime());
    }
}

Related

  1. alignWeek(Calendar timestamp)
  2. getBounceDatesOfWeek(Date date)
  3. getCurrentWeekNum(Date startDate, Date endDate)
  4. getCurrWeek()
  5. getEndOfWeek(Calendar cal)