|
Determine the day of the week |
|
|
This tip shows the ways to determine the day of the week in Java.
For the day of the week for today :
GregorianCalendar newCal = new GregorianCalendar( );
int day = newCal.get( Calendar.DAY_OF_WEEK );
For the day of the week for any date :
Calendar newCal = new GregorianCalendar();
newCal.set(1997, 2, 1, 0, 0, 0);
// BUG fix in Calendar class!
newCal.setTime(newCal.getTime());
int day = newCal.get(Calendar.DAY_OF_WEEK);
/*
also available :
newCal.get( Calendar.DAY_OF_MONTH )
newCal.get( Calendar.DAY_OF_WEEK_IN_MONTH )
newCal.get( Calendar.DAY_OF_YEAR )
newCal.get( Calendar.DATE )
*/
|
Related Tips
|