Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

Date Generation  RSS feed

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to generate next seven days Date from a new Date()???
 
Java Cowboy
Sheriff
Posts: 16084
88
Android IntelliJ IDE Java Scala Spring
  • 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.
 
Marshal
Posts: 60816
190
  • 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.
 
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stop! Joda time!
 
Ranch Hand
Posts: 338
  • 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
Sheriff
Posts: 16084
88
Android IntelliJ IDE Java Scala Spring
  • 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: 1952
7
Eclipse IDE Java
  • 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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jasper !!! :lol:
 
Ranch Hand
Posts: 624
IntelliJ IDE Java
  • 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
  • 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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any replies?
Regards
 
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's easy

 
ramya narayanan
Ranch Hand
Posts: 338
  • 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!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!