Java Programing laungage

java.util Projects

java.util Project 1

Determining the Day-of-Week to a Particular Date

In This programming tutorials, we can simply show the current day in word i.e. how we can find the day of a particular date of a week. Here, we can learn about the way of find it.

Previous Home Next

In this program, we are getting the day of the week using Calendar.DAY_OF_WEEK which is the special field of the Calendar class. It class is used to return the numeric value between 1 to 7.Here, each and every day is specified for the specific returned value like 1-Sunday, 2-Monday, 3-Tueseday, 4-Wednesday, 5-Thursday, 6-Friday and 7-Saturday. These specification is completed in the switch construct.

Example


package r4r;
import java.util.*;
public class determinedaytest {
public static void main(String[] args){
Calendar cal = Calendar.getInstance();
int day = cal.get(Calendar.DAY_OF_WEEK);
System.out.print("Today is:");
switch(day){
case 1: System.out.print("Sunday");
break;
case 2: System.out.print("Monday");
break;
case 3: System.out.print("Tueseday");
break;
case 4: System.out.print("Wednesday");
break;
case 5: System.out.print("Thursday");
break;
case 6: System.out.print("Friday");
break;
case 7: System.out.print("Saturday");
break;
}
System.out.print(".");
}
}

Previous Home Next