java yesterday date

94

java yesterday date -

LocalDate today = LocalDate.now();
LocalDate yesterday = today.minusDays(1);

// In string format
LocalDate today = LocalDate.now();
String yesterday = (today.minusDays(1)).format(DateTimeFormatter.ISO_DATE);

java create date object from yesterday -

Date date = DateUtils.addDays(new Date(), -1);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
return sdf.format(date);

java yesterday date -

Instant now = Instant.now();
Instant yesterday = now.minus(1, ChronoUnit.DAYS);
System.out.println(now);
System.out.println(yesterday);

Comments

Submit
0 Comments