Here's an easy method to return yesterday's date:
import java.time.LocalDateTime;
public class DoIt {
public static void main(String[] args) {
LocalDateTime yesterday = LocalDateTime.now().minusDays(1);
System.out.println(yesterday);
}
}
As you can see it's quite straight forward and simple. You just minus the number of days you wish to get. You can do this on a LocalDate or a LocalDateTime object.
From there you can do whatever you want with your past date.
No comments:
Post a Comment