Java获取今天是周几
时间: 2024-03-06 11:47:21 浏览: 96
java 这一天是星期几
你可以使用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。
阅读全文