java获取当前时间到10月15号的日期列表
时间: 2023-03-31 19:05:03 浏览: 80
您好,可以使用Java中的Calendar类和Date类来获取当前时间到10月15号的日期列表。具体实现可以参考以下代码:
```java
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
public class Main {
public static void main(String[] args) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date());
int currentMonth = calendar.get(Calendar.MONTH);
int currentYear = calendar.get(Calendar.YEAR);
List<Date> dateList = new ArrayList<>();
for (int i = currentMonth; i <= Calendar.OCTOBER; i++) {
calendar.set(currentYear, i, 1);
int maxDay = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
for (int j = 1; j <= maxDay; j++) {
calendar.set(Calendar.DAY_OF_MONTH, j);
Date date = calendar.getTime();
if (date.compareTo(new Date()) >= && date.compareTo(getOct15()) <= ) {
dateList.add(date);
}
}
}
for (Date date : dateList) {
System.out.println(date);
}
}
private static Date getOct15() {
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.MONTH, Calendar.OCTOBER);
calendar.set(Calendar.DAY_OF_MONTH, 15);
return calendar.getTime();
}
}
```
以上代码会输出当前时间到10月15号之间的日期列表。希望能够帮到您。
相关推荐
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)