First off I'm new in this incredible community. This is an amazing site. I'm happy to be part finally.
Every day I have to insert yesterday's data in the DB. For example, today May 22, I have to insert the data of the 21st from 00:00:00 to 23:59:59 in epoch time.
So far I get the epoch time from today with
long now = Instant.now().toEpochMilli();
How could I get yesterday's epoch time? and store the range of hours in two variables? Like
String startDay = 21/05/2020 00:00:00
String endDay = 21/05/2020 23:59:59
You can use java LocalDate like this:
final LocalDate now = LocalDate.now();
final LocalDate yesterday = now.minusDays(1);
final LocalDateTime start = yesterday.atStartOfDay();
final LocalDateTime end = yesterday.atTime(LocalTime.MAX);
And then format date to your desired format.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With