• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

How to find day from the week using date format?

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 259
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 233
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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;

}

}
}
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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");
reply
    Bookmark Topic Watch Topic
  • New Topic