Java Data Type How to - LocaleDate minus and plus








Question

We would like to know how to localeDate minus and plus.

Answer

import java.time.LocalDate;
/*from  w w w. j ava2s.  com*/
public class Main {
    public static void main(String[] args) {
        LocalDate today = LocalDate.now();

        // plus and minus operations
        System.out.println("10 days after today will be " + today.plusDays(10));
        System.out.println("3 weeks after today will be " + today.plusWeeks(3));
        System.out.println("20 months after today will be "
                + today.plusMonths(20));

        System.out.println("10 days before today will be "
                + today.minusDays(10));
        System.out.println("3 weeks before today will be "
                + today.minusWeeks(3));
        System.out.println("20 months before today will be "
                + today.minusMonths(20));

    }
}

The code above generates the following result.