Home > Java > JavaBase > body text

How to determine what day of the week a specified date is in java

王林
Release: 2019-11-13 13:33:47
Original
4239 people have browsed it

How to determine what day of the week a specified date is in java

1. First define an array of weeks. Because the array starts from 0, Sunday is put first, as shown in the figure:

How to determine what day of the week a specified date is in java

2. Get the Calendar object, and then operate the date and time, as shown in the figure:

How to determine what day of the week a specified date is in java

3. Set the passed in time into the Calendar object. As shown in the picture:

How to determine what day of the week a specified date is in java

4. Because the DAY_OF_WEEK of the operating environment starts on Sunday, you need to subtract 1 here, as shown in the picture:

How to determine what day of the week a specified date is in java

5. Return the execution result, as shown in the picture:

How to determine what day of the week a specified date is in java

#6. Write a test method to call the above completed method, as shown in the picture:

How to determine what day of the week a specified date is in java

7. Print out the execution results and display the day of the week, as shown in the figure:

How to determine what day of the week a specified date is in java

## Recommended tutorial:

Java tutorial

The above is the detailed content of How to determine what day of the week a specified date is in java. For more information, please follow other related articles on the PHP Chinese website!

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