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

Date Generation

 
Alpesh Rathod
Ranch Hand
Posts: 41
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to generate next seven days Date from a new Date()???
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This question doesn't seem to be about the SCJP exam. I will move this to a more appropriate forum for you.

Have a look at class java.util.Calendar for date arithmetic.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47293
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jesper Young wrote:Have a look at class java.util.Calendar for date arithmetic.
Also do a Google search for Apache Commons Calendar; you may find a Calendar class which is easier to use than the standard Java class.
 
Jelle Klap
Bartender
Posts: 1951
7
Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stop! Joda time!
 
ramya narayanan
Ranch Hand
Posts: 338
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Watch out for the plus method in the below link:
Date generation
Is it suffice?
Regards
Remember: This is a third-party functionality. so you need to download the appropriate jars & set it in the classpath.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ramya, your link is for the Groovy JDK. It will not work in plain Java, only in Groovy. The class Date from the standard JDK does not have plus or minus methods.

Also, for something simple like what Alpesh is asking, recommending a third-party library such as Apache Commons Calendar or Joda Time is overkill.


 
Jelle Klap
Bartender
Posts: 1951
7
Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jesper Young wrote:Also, for something simple like what Alpesh is asking, recommending a third-party library such as Apache Commons Calendar or Joda Time is overkill.


Sure, but Joda Time isn't a utility library meant to aliviate the headaches caused by Java's standard date/time API, it's a drop-in replacement that provides a much cleaner API and a more comprehensive feature set. In my opinion it's worth considering dropping the standard API in favor of Joda Time as soon as you need to perform even very basic date/time calculations. I guess my previous post was just motivated by a strong personal preference
 
Alpesh Rathod
Ranch Hand
Posts: 41
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jasper !!! :lol:
 
Mark Vedder
Ranch Hand
Posts: 624
IntelliJ IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For more info, here are some good JavaWorld articles on date math:

Calculating Java dates
Working in Java time : Learn the basics of calculating elapsed time in Java
 
ramya narayanan
Ranch Hand
Posts: 338
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Young,
Thanks for your solution.
But I think so that he has asked to display seven consecutive days from the current date & not the seventh date from the current date.
Regards
 
ramya narayanan
Ranch Hand
Posts: 338
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any replies?
Regards
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's easy

 
ramya narayanan
Ranch Hand
Posts: 338
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks wouter oet!
Anyhow as my contribution atleast I print out the output .

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