This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Java in General and the fly likes displaying 2 weeks dates Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "displaying 2 weeks dates" Watch "displaying 2 weeks dates" New topic
Author

displaying 2 weeks dates

sunita shaw
Ranch Hand

Joined: Apr 06, 2003
Posts: 45
can anyone tell me the code for extracting current date & displaying from it the next 2 weeks dates & also 1 week previous date using Gregorian Calendar.its very urgent.
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1815
Just curious, does it have to be GregorianCalendar or should you be using the generic Calendar class? Not that it truly matters to the answer, but it is shorter to just type "Calendar" and it more generic
To get the current date,

To get the date of one week ago:

To get the date two weeks hence:

(Note that you add three weeks, because we took one week away in the previous step. You could also get a new instance of the Calendar and add two weeks...this would produce more readable code, but is less efficient)
Once you have the start date and the end date, see
here to get the list of dates between the two.
You can then display the dates either using the .toString() method or, more likely, create a java.text.SimpleDateFormat to format the dates for you.


Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
Alternatively, you could create a loop that adds one day at a time for as many days as you wish.


Java API Documentation
The Java Tutorial
sunita shaw
Ranch Hand

Joined: Apr 06, 2003
Posts: 45
thanx joel , u've got it exactally what i want but can u please write a small java code for this problem, i dunno where i'm making the mistake,cant send u my code coz its too long,so just send me as soon as possible.
sunita shaw
Ranch Hand

Joined: Apr 06, 2003
Posts: 45
thanx joel , u've got it exactally what i want but can u please write a small java program for this problem, i dunno where i'm making the mistake,cant send u my code coz its too long,so just send me as soon as possible.
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1815
You should easily be able to create the java program from the code above and in the related link referenced above. If you are having other problems with your code (displaying the date, etc.) post them and we will be happy to help you with your problems.
If you feel that your code is too long to post here, feel free to send it to me via e-mail and I will take a look and see. While you can get my e-mail address from my profile, I'll save you the click: jsmcnary@earthlink.net
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: displaying 2 weeks dates
 
Similar Threads
displaying 2 weeks dates
Date Displaying issue
passed with 155... is that possible?
How to get weeks for a particular year with Calendar object
Date difference, with the table containing null values for date