Get Yesterday's Date Using Java's Time API

Next

In order to get yesterday's date, first find the current date, and then subtract one day from it.

The minus method will return a copy of the date with the specified amount subtracted.


import java.time.LocalDate;
import java.time.Period;

public final class DateUtility {

    private DateUtility() {}

    public static LocalDate getYesterday() {
        return LocalDate.now().minus(Period.ofDays(1));
    }

}