Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Problems with Calendar.get(Calendar.DAY_OF_WEEK)

807606May 4 2007 — edited May 4 2007
I 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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 1 2007
Added on May 4 2007
5 comments
627 views