This example shows how to find the number of weeks between two dates using Java 8 date time api and Joda time. We will set the start date to January 1, 2005 and the end date to January 1, 2006. Then we will find the number of weeks between the start date and end date which equates to 52 weeks.
Java 8 Date and Time API
This snippet will find the difference between two dates in weeks using java 8 Duration.between and ChronoUnit.WEEKS.between. Both approaches will calculate the amount of time between two temporal objects in the form of weeks.
Joda Time
Using joda, this snippet will calculate number of weeks between two dates using Weeks.weeksBetween.