javadatecalendar

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");

Solution

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

    date.set(2010, Calendar.MARCH, 7);