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

Ever feel like no one is listening?

 Ever have that feeling that no one is listening to you? Yeah, that feeling. It can be a strong feeling to have, a hurtful feeling also. The...