Friday, August 3, 2007

JAVA: A Method to Get Current Day of Week

Hello everybody, here is the method that returns the current day of week.

public static String getCurrentDayofWeek()
{
String DAY="";
Calendar cal =Calendar.getInstance();
int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
switch (dayOfWeek)
{
case 1:
DAY="SUNDAY";
break;
case 2:
DAY="MONDAY";
break;
case 3:
DAY="TUESDAY";
break;
case 4:
DAY="WEDNESDAY";
break;
case 5:
DAY="THRUSDAY";
break;
case 6:
DAY="FRIDAY";
break;
case 7:
DAY="SATURDAY";
break;
}
return DAY;
}

No comments: