We can use the Calendar class to determine the day of the week.
The Calendar class is an abstract class. In actual use, it implements objects of specific subclasses and only needs to be created using the getInstance method.
(Video tutorial recommendation: java video)
Method to create a Calendar object representing the current date of the system:
Calendar c = Calendar.getInstance();//默认是当前日期
Specific code As follows:
public class Test { public static void main(String[] args) { String[] weekDays = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"}; Calendar calendar=Calendar.getInstance(); System.out.println("今天是"+weekDays[calendar.get(Calendar.DAY_OF_WEEK)-1]); } }
Recommended tutorial: java entry program
The above is the detailed content of How to determine what day of the week today is in java. For more information, please follow other related articles on the PHP Chinese website!