| Author |
how can i get the date on next sunday
|
vijay shanker
Ranch Hand
Joined: Oct 26, 2007
Posts: 88
|
|
hi all, any way i can do this or i have follow all the process of setting values on the calendar object. cheers vijay
|
 |
Paul Sturrock
Bartender
Joined: Apr 14, 2004
Posts: 10336
|
|
|
If you are just trying to find out what the date is in n days time, you can just add n days to the current date. The Calendar class has an add method for this purpose.
|
JavaRanch FAQ HowToAskQuestionsOnJavaRanch
|
 |
vijay shanker
Ranch Hand
Joined: Oct 26, 2007
Posts: 88
|
|
hi Paul, i need to get the date on the coming next sunday.
|
 |
Paul Sturrock
Bartender
Joined: Apr 14, 2004
Posts: 10336
|
|
|
So...you already know the date and you just want to create a Calendar for that date? They you are right, you need to set the individual fields of your Calendar manually (using one of the set methods).
|
 |
vijay shanker
Ranch Hand
Joined: Oct 26, 2007
Posts: 88
|
|
|
i dont know the date of sunday paul. what i only aware is today. i have to create a date object for next sunday.
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19232
|
|
Use Calendar.get(Calendar.DAY_OF_WEEK) to determine what day of the week it is. Then subtract that from Calendar.SUNDAY, and add 7 if needed. Pass that number to Calendar.add: If you want the next Sunday on a Sunday as well you should also add 7 if days == 0, making the guard "days <= 0".
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Mark Vedder
Ranch Hand
Joined: Dec 17, 2003
Posts: 624
|
|
|
You can also take a look at the Joda Time API which has some great methods to make date and time math a bit more straight forward than the Java date & time APIs.
|
 |
vijay shanker
Ranch Hand
Joined: Oct 26, 2007
Posts: 88
|
|
thanks Rob, it was great i was not able to device a simple algorithm for all the day cheers vijay
|
 |
 |
|
|
subject: how can i get the date on next sunday
|
|
|