Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Create an Array of Weeks

 
Steve Dyke
Ranch Hand
Posts: 1616
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author & internet detective
Marshal
Posts: 34087
337
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Steve Dyke
Ranch Hand
Posts: 1616
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have this so far where I send some date as a parameter:

 
Edwin Dalorzo
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1282
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I would give you some more code but this may be a homework assignment.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34087
337
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic