• 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

displaying 2 weeks dates

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 1844
Eclipse IDE Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Alternatively, you could create a loop that adds one day at a time for as many days as you wish.
 
sunita shaw
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1844
Eclipse IDE Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic