File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Create an Array of Weeks Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Create an Array of Weeks" Watch "Create an Array of Weeks" New topic
Author

Create an Array of Weeks

Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1439
    
    1
Can someone help me create an array of 52 weeks(three elements) with each week ending on Sunday and the first week will start on the following Sunday form current date. Element 1 = First date of week, Element 2 Last Date of week, and Element 3 a string of Last Date of week such as "5/18".
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30382
    
150

Steve,
What do you have so far?

Do you know how to:
1) Create an array of 52 string elements?
2) Get the current date?
3) Transform a date into the format mm/dd as a string?
4) Find the next sunday from today?
5) Find the beginning of the current week?


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1439
    
    1
I have this so far where I send some date as a parameter:

Edwin Dalorzo
Ranch Hand

Joined: Dec 31, 2004
Posts: 961
Well, I am not very sure to understand your explanation of the problem. I seem to understand that your weeks go from Monday to Sunday, and you want the date of such Monday and Sunday starting from today, up to 52 weeks.

You can get the date of this week's Monday like this:



You can get the date of this week's Sunday like this:



Then you can easily move to the next week:



I hope that helps!
[ May 16, 2008: Message edited by: Edwin Dalorzo ]
Nicholas Jordan
Ranch Hand

Joined: Sep 17, 2006
Posts: 1282

I would give you some more code but this may be a homework assignment.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30382
    
150

Steve,
Take a look at the Calendar API a bit more. In particular the cal.add() and cal.get() methods. Note that add() does both addition/subtraction and get() can get you the month/date/year.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Create an Array of Weeks