• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to find day from the week using date format?

 
Kondal reddy
Greenhorn
Posts: 22
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can I find day from the week using date format like 27/02/2006. from this date format I have to find that day is Monday.
I mean using date format how we can find day(like monday, or tuesday or wednus day) from week.
 
karthikeyan Chockalingam
Ranch Hand
Posts: 259
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Please refer http://java.sun.com/j2se/1.4.2/docs/api/constant-values.html#java.util.Calendar.YEAR
for constant values

[ February 27, 2006: Message edited by: karthi keyan ]
[ February 27, 2006: Message edited by: karthi keyan ]
 
Arun Boraiah
Ranch Hand
Posts: 233
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
import java.util.*;

public class FindDay {

public static void main(String args[]){
Calendar cal = Calendar.getInstance();
cal.set(2006,2,27);
System.out.println("DAY_OF_WEEK =" + cal.get(Calendar.DAY_OF_WEEK));

switch(cal.get(Calendar.DAY_OF_WEEK)){
case Calendar.MONDAY:
System.out.println("Monday");
break;

case Calendar.TUESDAY:
System.out.println("TUESDAY");
break;

case Calendar.WEDNESDAY:
System.out.println("WEDNESDAY");
break;

case Calendar.THURSDAY:
System.out.println("THURSDAY");
break;

case Calendar.FRIDAY:
System.out.println("FRIDAY");
break;

case Calendar.SATURDAY :
System.out.println("SATURDAY");
break;

case Calendar.SUNDAY :
System.out.println("SUNDAY");
break;

}

}
}
 
Christophe Verré
Sheriff
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want to parse "27/02/2006" as it is,
You may want to have a look at :

SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");
Date date = format.parse("27/02/2006");
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic