aspose file tools*
The moose likes Beginning Java and the fly likes Date Generation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Date Generation " Watch "Date Generation " New topic
Author

Date Generation

Alpesh Rathod
Ranch Hand

Joined: Jan 06, 2009
Posts: 41
How to generate next seven days Date from a new Date()???


Thanks,
Alps
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14104
    
  16

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.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38348
    
  23
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

Joined: Mar 10, 2008
Posts: 1760
    
    7

Stop! Joda time!


Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
ramya narayanan
Ranch Hand

Joined: Oct 06, 2008
Posts: 338
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

Joined: Aug 16, 2005
Posts: 14104
    
  16

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

Joined: Mar 10, 2008
Posts: 1760
    
    7

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

Joined: Jan 06, 2009
Posts: 41
Thanks Jasper !!! :lol:
Mark Vedder
Ranch Hand

Joined: Dec 17, 2003
Posts: 624

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

Joined: Oct 06, 2008
Posts: 338
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

Joined: Oct 06, 2008
Posts: 338
Any replies?
Regards
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

That's easy



"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
ramya narayanan
Ranch Hand

Joined: Oct 06, 2008
Posts: 338
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
 
subject: Date Generation