I wrote few lines of code which doesn't work correctly. Why? Could sb explain me?
Calendar date = Calendar.getInstance();
date.set(2010, 03, 7);
if(date.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY)
System.out.println("OK");
Checking a Weekend using LocalDate Each integer value represents a different weekday. 1 represents Monday, and so on 6 represents Saturday and 7 represents Sunday. By comparing the above integer value with days in DayOfWeek enum, we can determine if a date is a weekday or weekend.
To avoid making mistakes, you can use Calendar static values for the month, e.g. :
date.set(2010, Calendar.MARCH, 7);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With