Menu
Topics Index
...
`

Identify The Week Day Of The Given Date


If you need explanation Read this topic

If you need Answer Take test on this topic

Write a program to identify the week day of the given date.

Input (Date) Output (String)
18 January 2013 Friday
19 June 2013 Wednesday
25 December 2005 Sunday
7 July 2001 Saturday
14 November 2044 Monday


import java.util.*;
import java.text.*;
class IdentifyTheDayOfTheDate1
{
    public static void main(String s[])
    {
        System.out.println("Day of 18 January 2013 is : " + dayOfDate("18 January 2013"));

    }


    public static String dayOfDate(String date) {
    String result = null;
    return result;
    }

}
Topic: Locale Class In Java

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

to print a particular day on a given date..... we need to take the help of calendar claas of java... about calendar class -->> TheCalendaris an abstract class that provides methods for converting between time and calendar fields. Also, the class provides fields and methods for implementing a concrete calendar system.we have to make use of getinstance() -->>which returns a general object of this type, whose calendar fields have been initialized with the current date and time. For example:1Calendar calendar = Calendar.getInstance();.........TheCalendarprovides getter and setter methods for its fields:*.public final int get (int field)*.public final void set (int field, int value).......using calender.set()we will set the values. usimg the calender method ...--Calendar calendar =new GregorianCalendar(yy,mm,dd)...we wll fed the spexified date.. .......another method can also be used to find the day of the week on a given date wich does not involve the use of any calender class.... simply Aptitude logic can help in finding the day of any date....... here the logic I am using is generally usd in solving aptitude qstns based on date..... we have to model this logic into a java program.......... for this lets undrstand the concept behind this-->>1) odd days   - in a given period.  ,no.  of days more than the cmplt weeks are odd days.... countng of odd days -- 2 ordinary yr has 365 days i. e 52 weeks  1 day hence 1 ordinary yr has 1 odd day.... now in a leap yr -52 wks n 2 odd days.... and in 100 yrs there are 76 ordinary yrs and 24 leap yrz i.e (76*1 24*2 ) =124 odd days or (17 weeks   5days) as wks are complt periods hence ignore dem and we have 5 odd days in 100 yrs.. similarly 200 yrs=3 odd days 300yrs=1 odd day 400,800,1200,1600,2000 yrs has 0odd days.... now comimg to prgrm design..... store the days sun,mon, tue in an array week strtng frm zero......  now... for a gvn date count the numbr of odd days... for ex - 4 june 2002 .... we have (2001 yrs   period frm 1.1.2002 to 4.6.2002 ........so frm prgrm pt of view y=yr-1 .....now we have to find total odd days in y yrs...... if (y<2000) y=y-1600 else y=y-2000 here we are subtractng it wid 1600 or 2000 since no.  if odd days in 1600 yrs are zero... now we have to find the odd days in remaing yrz....... and so on...... aftr finding total odd days.... then the day of week will be week[odd day] be the answer

Posted by Asma Mujtaba Khan    2014-12-29 06:38:31


To identify the week day from given date we have to use calender and GregorianCalendar class in java.GregorianCalendar is a concrete subclass of Calendar and provides the standard calendar system used by most of the world.

Following steps needs to be followed to identify the week day from given data:

1) Create object of Calendar class by passing it the object GregorianCalendar.

--Calendar c=new GregorianCalendar();

2)Calendar class has set method in various forms to set the values for year,month and day_of_month.

--set(int year, int month, int date)
    Sets the values for the calendar fields YEAR, MONTH, and DAY_OF_MONTH.

3)The date given in question is in String format we have to use split(" ") function of String class to get the value of year,month and day_of_month individually.

--String s[]=date.split(" ");
String array should be converted to integer by explicit typecasting.

4)use set function of calender.

--c.set(yyyy,mm,dd);

5)There are various static int variables in calender to get the specific thing from the date created by set method.get() function of calendar class is used to get the field value.

--get(int field)
Returns the value of the given calendar field.    

6)we use "DAY_OF_WEEK" variable to display which day of week is specified in given date.

--int DAY_OF_WEEK=c.get(Calendar.DAY_OF_WEEK);

7)we use swich case to print the day from the integer DAY_OF_WEEK.
Eg: Sunday -->  Day of Week 1

swich(DAY_OF_WEEK)
{
    case 1:
    System.out.print("sunday");
    break;
}
and so on for each day.

Posted by Mânïshå Mùlchåndânï    2014-12-29 10:48:04


This dose is now closed and the winners are Asma Mujtaba Khan,  for 'First Correct Comment', Mânïshå Mùlchåndânï,  for 'Second Correct Comment'. The 'lucky liker' is Ananthoju Arun Chary. Please login into Merit Campus using facebook, to claim your recharge. Go to http://java.meritcampus.com/earnings to raise the recharge.

Posted by Merit Campus    2015-01-03 05:07:25


© meritcampus 2019

All Rights Reserved.

Open In App