Thursday, March 7, 2024

Get Yesterday's Date

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

A Placebo?

 At times I wonder if my medication is just a placebo. That is a medication that usually has no effect on a disease. Am I dreaming it all up...