Here we are find start and end date if date is 30 days older from today or current date in java.
- User LocalDate.now() method to get the current date.
- Now minus the 30 days from current date use currentDate.minusDays(30) method.
- This DateTimeFormatter.ISO_DATE that formats or parses a date with the offset such as ‘2025-05-20’.
- After formating we map the start date and end date in hashmap with key,value pair.
- Print the start and end date from dateParams.
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.Map;
public class MinusDaysProgram {
public static void main(String[] args) {
LocalDate currentDate = LocalDate.now();
LocalDate startDate = currentDate.minusDays(30);
DateTimeFormatter formatter = DateTimeFormatter.ISO_DATE;
Map<String, String> dateParams = new HashMap<String, String>();
String startDateString = startDate.format(formatter);
String endDateString = currentDate.format(formatter);
dateParams.put("start_date", startDateString);
dateParams.put("end_date", endDateString);
System.out.println("find start and end date after 30 days minus is :- "+dateParams);
}
}
Output :-
find start and end date after 30 days minus is :- {end_date=2025-05-22, start_date=2025-04-22}