Problems with Calendar.get(Calendar.DAY_OF_WEEK)
807606May 4 2007 — edited May 4 2007I need to know wich day of the week is a given date, i mean, the user gives me 05.03.2007 and i need to know if it's Saturday.
To know it, i do this:
GregorianCalendar calendario = new GregorianCalendar();
calendario.clear();
calendario.setFirstDayOfWeek(6);
calendario.set(calendario.MONTH, month);
calendario.set(calendario.DAY_OF_MONTH, day);
calendario.set(calendario.YEAR, year);
//month, day and year are int variable wich contains the given date.
day = calendario.get(calendario.DAY_OF_WEEK);
system.out.println("Wich day is it?-> "+day);
This code, seems to work, but if you set the "today" date (month=5, day=4, year=2007) it prints: "Wich day is it?->2" wich is Tuesday (and today is friday!)
What's happening? I'm using JDK 1.4