
How can i get the day for the user input data ?

Hello Friend,
You can use the following code:
import java.util.*;
import java.text.*;
class CheckDay{
public static void main(String[] args){
Scanner input=new Scanner(System.in);
System.out.println("Enter date(1-31):");
int dd=input.nextInt();
System.out.println("Enter month(1-12): ");
int month=input.nextInt()-1;
System.out.println("Enter year: ");
int year=input.nextInt();
Date date= (new GregorianCalendar(year, month, dd)).getTime();
SimpleDateFormat f = new SimpleDateFormat("EEEE");
String day=f.format(date);
System.out.println(day);
}
}
Thanks

thank you for the program.... it was very useful to me...but how can i find a day without using the SimpleDateFormat class..

By Nishanth Thomas - Insolutions Global Bangalore
package example;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import com.sun.org.apache.xerces.internal.impl.xpath.regex.ParseException;
public class test3 {
/**
* @param args
* @throws java.text.ParseException
*/
public static void main(String[] args) throws java.text.ParseException {
// TODO Auto-generated method stub
try {
String str_date="11-jan-07";
DateFormat formatter ;
Date date ;
formatter = new SimpleDateFormat("dd-MMM-yy");
date = (Date)formatter.parse(str_date);
// System.out.println("Today is " +date );
SimpleDateFormat sdf;
sdf = new SimpleDateFormat("DD/MM/yyyy");
System.out.println("DAte " + sdf.format(date));
} catch (ParseException e)
{
System.out.println("Exception :"+e); }
}
}

Convert into format 23/08/2007 if given date is 23/08/2007 or 23-aug-2010
By Nishanth Thomas - Insolutions Global Bangalore
package example;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import com.sun.org.apache.xerces.internal.impl.xpath.regex.ParseException;
public class test3 {
/**
* @param args
* @throws java.text.ParseException
*/
public static void main(String[] args) throws java.text.ParseException {
// TODO Auto-generated method stub
String str_date="23/08/2007"; // or 23-aug-2010
DateFormat formatter ;
Date date ;
SimpleDateFormat sdf = null;
try{
formatter = new SimpleDateFormat("dd/MM/yyyy");
date = (Date)formatter.parse(str_date);
//System.out.println(formatter);
sdf = new SimpleDateFormat("dd/MM/yyyy");
System.out.println("DAte " + sdf.format(date));
}catch (Exception e){
// e.printStackTrace();
System.out.println(" error");
try{
formatter = new SimpleDateFormat("dd-MMM-yyyy");
date = (Date)formatter.parse(str_date);
// System.out.println("Today is " +date );
sdf = new SimpleDateFormat("dd/MM/yyyy");
System.out.println("DAte " + sdf.format(date));
} catch (ParseException e1)
{
System.out.println("Exception :"+e1);
}
}
}
}
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.