I want to show the all week start dates between two dates.
Suppose I have selected start date as 25th July 2023 - 25th Aug 2023, then it should return the results:
25 July 2023
2 Aug 2023
9 Aug 2023
16 Aug 2023
23 Aug 2023
If have lib period day, week, month, year in lunar calendar Vietnamese or Chinese
List<LocalDate> weekDates = new ArrayList<>();
LocalDate tmp = LocalDate.of(2023, 7, 25);
LocalDate end = LocalDate.of(2023, 8, 25);
// Loop until we surpass end date
while(tmp.isBefore(end)) {
weekDates.add(tmp);
tmp = tmp.plusWeeks(1);
}
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd LL yyyy");
for (int i = 0; i < weekDates.size(); i++) {
String formattedString = weekDates.get(i).format(formatter);
System.out.println(formattedString);
}
Your code looks mostly correct for generating the start dates of each week between two given dates. However, there are a couple of things to note:
The code you provided already generates the desired start dates for each week between July 25, 2023, and August 25, 2023.
You are using the DateTimeFormatter to format the output dates. In your comment, you mentioned lunar calendar periods, but your code is using the Gregorian calendar. If you want to convert these dates to the lunar calendar, you'll need to incorporate a lunar calendar library or API, which may require additional code.
Here's your code with comments to make it clear:
If you need to convert these dates to the lunar calendar, you'll need to use a lunar calendar library or API specific to the Vietnamese or Chinese lunar calendar, as lunar calendars are different from the Gregorian calendar.