Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How check if today is sunday with Java Calendar

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");
like image 817
Kamil Avatar asked Mar 07 '10 12:03

Kamil


People also ask

How do I know if my LocalDate is Weekend?

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.


1 Answers

To avoid making mistakes, you can use Calendar static values for the month, e.g. :

date.set(2010, Calendar.MARCH, 7);
like image 174
Desintegr Avatar answered Sep 28 '22 20:09

Desintegr