File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how can i get the date on next sunday

 
vijay shanker
Ranch Hand
Posts: 88
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
vijay shanker
Ranch Hand
Posts: 88
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Paul,
i need to get the date on the coming next sunday.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 88
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20388
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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".
 
Mark Vedder
Ranch Hand
Posts: 624
IntelliJ IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 88
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Rob,

it was great i was not able to device a simple algorithm for all the day

cheers

vijay
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic