First define an array of weeks. Because the array starts from 0, Sunday is put first, as shown in the figure:
Get the Calendar object, and wait to operate the date and time, as shown in the figure:
Set the passed in time into the Calendar object, as shown in the figure:
Because the DAY_OF_WEEK of the running environment starts from Sunday, you need to subtract 1 here, as shown in the figure:
After execution The result is returned, as shown in the figure:
Write a test method to call the above completed method, as shown in the figure:
Print The execution result is displayed and the day of the week is displayed, as shown in the figure:
## Recommended tutorial:Getting started with java development
The above is the detailed content of Calculate the day of the week for a specified date in java. For more information, please follow other related articles on the PHP Chinese website!