[ajug-members] Day of week calculation
Steven Wisener
swisener at gmail.com
Wed Jul 14 10:45:04 EDT 2004
You are just printing out the Calendar constants, which never change.
You need to use the get() method to get the correct value, for
example:
import java.util.Calendar;
import java.util.Date;
public class DowTest {
public static void main(final String[] args) {
final Calendar cal = Calendar.getInstance();
System.out.println(cal.get(Calendar.DAY_OF_WEEK));
cal.add(Calendar.DAY_OF_WEEK, -1);
System.out.println(cal.get(Calendar.DAY_OF_WEEK));
}
}
This will print out 2 different days of the week.
--Steven
----- Original Message -----
From: Barnes, Michael D <michael.barnes at bellsouth.com>
Date: Wed, 14 Jul 2004 09:35:01 -0500
Subject: [ajug-members] Day of week calculation
To: ajug-members at ajug.org
I need some help getting the Day of week from a day.
I am trying to use the following code but keep getting the same answer
no matter what the date is.
GregorianCalendar gc = new GregorianCalendar();
//GregorianCalendar gc = new
GregorianCalendar(dateSelected.getYear(),dateSelected.getMonth(),dateSelected.getDay()-1);
gc.setTime(dateSelected);
java.util.Date d = gc.getTime();
System.out.println("Date Year = " + d.getYear());
int dayOfMonth =gc.DAY_OF_WEEK;
System.out.println("Date of the Month : " + dayOfMonth);
System.out.println("Date of the Month : " + gc.DATE);
What am I doing wrong.
Thanks
Mike Barnes
More information about the ajug-members
mailing list