search
HomeJavaJavaBaseCalculate the day of the week for a specified date in java

Calculate the day of the week for a specified date in java

Nov 20, 2019 pm 02:28 PM
javaSpecify dateDay of the weekcalculate

Calculate the day of the week for a specified date in java

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

Calculate the day of the week for a specified date in java

Get the Calendar object, and wait to operate the date and time, as shown in the figure:

Calculate the day of the week for a specified date in java

Set the passed in time into the Calendar object, as shown in the figure:

Calculate the day of the week for a specified date in java

Because the DAY_OF_WEEK of the running environment starts from Sunday, you need to subtract 1 here, as shown in the figure:

Calculate the day of the week for a specified date in java

After execution The result is returned, as shown in the figure:

Calculate the day of the week for a specified date in java

Write a test method to call the above completed method, as shown in the figure:

Calculate the day of the week for a specified date in java

Print The execution result is displayed and the day of the week is displayed, as shown in the figure:

Calculate the day of the week for a specified date in java

## 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!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.