java determines whether a date is a weekend:
/** * 判断是否是周末 * @return */ private boolean isWeekend(Calendar cal){ int week=cal.get(Calendar.DAY_OF_WEEK)-1; if(week ==6 || week==0){//0代表周日,6代表周六 return true; } return false; }
The Calendar class is an abstract class that provides us with related functions for date calculation, such as: year, month, Display and calculation of day, hour, minute and second.
GregorianCalendar is a concrete subclass of Calendar that provides the standard calendar system used by most countries in the world.
Calendar.DAY_OF_WEEK——The day of the week, the value of 1--7, corresponding to: Sunday, Monday, Tuesday, Wednesday....Saturday
Getting the day of the week Calendar.DAY_OF_WEEK - The reason for 1
Calendar.DAY_OF_WEEK in Java actually means: the day of the week, so it will be affected by the day of the week when the first day is.
Some areas use Sunday as the first day of the week, while some areas use Monday as the first day of the week. These two situations need to be distinguished.
For more java knowledge, please pay attention to the java basic tutorial column.
The above is the detailed content of Java determines whether a date is a weekend. For more information, please follow other related articles on the PHP Chinese website!