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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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: 726
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: 726
Thanks all for fixing my problem

Best regards
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19541
    
  16

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: 36478
    
  16
If you simply wish to display the day of the week, it might be easier to use a %t tag and the printf method.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Finding day in the date
 
Similar Threads
converting date string into Calendar.Day of Year
Problem with date and time?
Add 1 day to a date?
How to get tomorrow's date?
simpledateformat