java判断当前时间是否为周一
时间: 2023-09-11 16:12:04 浏览: 125
可以使用Java中的Calendar类和get方法来判断当前时间是否为周一,具体代码如下:
```java
import java.util.Calendar;
public class CheckMonday {
public static void main(String[] args) {
Calendar calendar = Calendar.getInstance();
int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
if (dayOfWeek == Calendar.MONDAY) {
System.out.println("Today is Monday.");
} else {
System.out.println("Today is not Monday.");
}
}
}
```
其中,通过`Calendar.getInstance()`方法获取当前时间的Calendar实例,然后通过`get(Calendar.DAY_OF_WEEK)`方法获取当前时间是一周中的第几天,周一为第二天,所以判断是否为周一即判断`dayOfWeek`是否等于`Calendar.MONDAY`。
阅读全文
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![txt](https://img-home.csdnimg.cn/images/20241231045021.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![py](https://img-home.csdnimg.cn/images/20250102104920.png)