Opposite of adding weeks to a java date, this example shows how to subtract weeks from a date using java's Calendar.add, java 8 date time api, joda’s DateTime.minusWeeks and apache commons DateUtils.addWeeks. In each of the examples below, we will set a date that represents new years day or January 1st. Then we will subtract one week returning a date representing christmas or December 25th.
Straight up Java
Output
Java 8 Date and Time API
Java 8 LocalDateTime.minusWeeks will return a copy of the LocalDateTime with the specified number of weeks subtracted.
Output
Joda Time
Joda DateTime.minusWeeks will return a copy the DateTime minus the specified number of weeks.
Output
Apache Commons
Apache commons DateUtils.addWeeks will adds a number of weeks, in this case a negative number of weeks, to the date returning a new object.