Home  >  Article  >  Java  >  How to determine what day of the week today is in java

How to determine what day of the week today is in java

王林
王林Original
2020-05-14 15:34:483342browse

How to determine what day of the week today is in java

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn