Home > Java > javaTutorial > body text

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

王林
Release: 2020-05-14 15:34:48
Original
3346 people have browsed it

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();//默认是当前日期
Copy after login

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]);
    }
}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!