
java determines the day of the week the current date is:
/**
* 判断当前日期是星期几<br>
* <br>
* @param pTime 修要判断的时间<br>
* @return dayForWeek 判断结果<br>
* @Exception 发生异常<br>
*/
public static int dayForWeek(String pTime) throws Exception {
format = new SimpleDateFormat("yyyy-MM-dd");
Calendar c = Calendar.getInstance();
c.setTime(format.parse(pTime));
int dayForWeek = 0;
if(c.get(Calendar.DAY_OF_WEEK) == 1){
dayForWeek = 7;
}else{
dayForWeek = c.get(Calendar.DAY_OF_WEEK) - 1;
}
return dayForWeek;
}It should be noted that Sunday is the first day of the week internationally, and the DAY_OF_WEEK provided in Calendar The week obtained also starts with Sunday.
The Chinese custom is to start the week on Monday, so it needs to be set according to the actual needs of the project.
The Calendar class provides some methods for conversion between calendar fields such as YEAR, MONTH, DAY_OF_MONTH, HOUR, etc., and provides some methods for operating calendar fields (such as getting the date of next week).
For more java knowledge, please pay attention to java basic tutorial.
The above is the detailed content of How to determine the day of the week in java?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

Zend Studio 13.0.1
Powerful PHP integrated development environment

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

SublimeText3 English version
Recommended: Win version, supports code prompts!

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.





