Java获取今天是周几
时间: 2024-03-06 20:47:21 浏览: 99
Java课程论文——输入日期,计算星期
5星 · 资源好评率100%
你可以使用Java中的Calendar类来获取今天是周几。以下是示例代码:
```
import java.util.Calendar;
public class Main {
public static void main(String[] args) {
Calendar calendar = Calendar.getInstance();
int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
String[] weekDays = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
System.out.println("Today is " + weekDays[dayOfWeek - 1]);
}
}
```
这个程序将输出今天是星期几,例如:Today is Monday。
阅读全文