java获得当月的双休日
时间: 2023-11-10 07:04:26 浏览: 104
可以使用Java的Calendar类来获取当月的所有日期,然后判断哪些日期是双休日。具体实现如下:
```java
import java.util.Calendar;
public class Main {
public static void main(String[] args) {
Calendar calendar = Calendar.getInstance();
int year = calendar.get(Calendar.YEAR);
int month = calendar.get(Calendar.MONTH) + 1;
int days = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
for (int i = 1; i <= days; i++) {
calendar.set(year, month - 1, i);
int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
if (dayOfWeek == Calendar.SATURDAY || dayOfWeek == Calendar.SUNDAY) {
System.out.println(year + "-" + month + "-" + i);
}
}
}
}
```
阅读全文