aspose file tools*
The moose likes Java in General and the fly likes Finding day in the date Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Finding day in the date" Watch "Finding day in the date" New topic
Author

Finding day in the date

Farakh khan
Ranch Hand

Joined: Mar 22, 2008
Posts: 732
Hello,

How can I know the day of the date e.g. 27/3/2011

Thanks & best regards
John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
Form a Calendar instance with the date value and get the day by getting Calendar.DAY_OF_WEEK
Vijay Tidake
Ranch Hand

Joined: Nov 04, 2008
Posts: 146

Hi,


Hope this helps

Thanks


The important thing is not to stop questioning.Curiosity has its own reason for existing.
John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
... and if you are using Calendar.DAY_OF_WEEK note that Sunday = 1 & so on.
Farakh khan
Ranch Hand

Joined: Mar 22, 2008
Posts: 732
Thanks all for fixing my problem

Best regards
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19672
    
  18

Vijay Tidake wrote:System.out.println(cal.getTime().getDay());[/code]

Hope this helps

Not really. cal.getTime() returns a Date object, and Date.getDay() is deprecated and should not be used. You already have a Calendar object, use that. So once you have that, use cal.get(Calendar.DAY_OF_WEEK).

As for the return value, compare that to the constants Calendar.SUNDAY, Calendar.MONDAY, ..., Calendar.SATURDAY. These are valued from 1 to 7, but your code will be more readable and less error-prone.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38416
    
  23
If you simply wish to display the day of the week, it might be easier to use a %t tag and the printf method.
 
wood burning stoves
 
subject: Finding day in the date