Java Data Type How to - Get date in two weeks before








Question

We would like to know how to get date in two weeks before.

Answer

Java has a built-in date library, java.time bundled with Java 8.

The following code shows how to use the minusWeeks to get the date in two weeks before.

import java.time.LocalDate;

public class Foo {
    public static void main(String[] args) {
        System.out.println(LocalDate.parse("2014-05-03").minusWeeks(2));
    }
}

The code above generates the following result.