Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

day of week

Status
Not open for further replies.

sesJ

Programmer
Joined
Feb 2, 2004
Messages
3
Location
DE
Hi,
How to find the name of the day from a given input like "1/1/04" using Java ? The answer should be Sunday in this case.
Thanks in advance.
sesJ
 
Hi,

Hope this will help you...But 1/1/04 is not sunday its thursday....

public void getDayOfWeek() {

String inputDate = "2/1/04";
Calendar now = Calendar.getInstance();
String[] weekArray = {"Sunday", "Monday" , "Tuesday", "Webnesday", "Thursday", "Friday","Saturday"};
SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yy");
System.out.print(" " + inputDate + " parses as ");
try {
now.setTime(formatter.parse(inputDate));
System.out.println(formatter.format(now.getTime()));
System.out.println(weekArray[now.get(Calendar.DAY_OF_WEEK)-1]);
} catch (ParseException e) {
System.out.println("Unparseable using " + formatter + ".");
}
}

Cheers,
Venu
 
Hi, Thanks for the replies.
sesJ
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top