| Author |
Finding day in the date
|
Farakh khan
Ranch Hand
Joined: Mar 22, 2008
Posts: 672
|
|
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: 672
|
|
Thanks all for fixing my problem
Best regards
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
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
How To Ask Questions How To Answer Questions
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32611
|
|
|
If you simply wish to display the day of the week, it might be easier to use a %t tag and the printf method.
|
 |
 |
|
|
subject: Finding day in the date
|
|
|