Home Java Example Java Util Determining the Day-of-Week for a Particular Date



Determining the Day-of-Week for a Particular Date
Posted on: April 16, 2007 at 12:00 AM
This section simply show the current day in word i.e. the Day of Week for a particular date.

Determining the Day-of-Week for a Particular Date

     

This section simply show the current day in word i.e. the Day of Week for a particular date. Here, you can learn about the way of doing that.

Following program helps you for showing the current day in word. This program gets the day of the week using Calendar.DAY_OF_WEEK i.e. the special field of the Calendar class. It returns 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.

Here is the code of the program:

import java.util.*;

public class DayOfWeek{
  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(".");
  }
}

Download this example.

Related Tags for Determining the Day-of-Week for a Particular Date:
cdateiothisfortolearneareilsectionulartcurrentinpartcalcalcntparweekcacalculateicuhowdayseeatlatekislleaarrtssrenthono


More Tutorials from this section

Ask Questions?    Discuss: Determining the Day-of-Week for a Particular Date  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.