• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Create an Array of Weeks

 
Ranch Hand
Posts: 2206
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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".
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 2206
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have this so far where I send some date as a parameter:

 
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I would give you some more code but this may be a homework assignment.
 
Jeanne Boyarsky
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
On top of spaghetti all covered in cheese, there was this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic