Win a copy of Murach's MySQL this week in the JDBC and Relational Databases forum!
  • 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

Printing all days of the week

 
Ranch Hand
Posts: 89
Netscape MySQL Database Windows XP
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In part of my program I try to get the dates of this week assigned to a JComboBox. While developing I check my results. And the result is not to my liking. Might you have a suggestion for me?



In this code I decide on what date this weeks Monday is. From that date I print out the dates of this weeks days. For this week beginning Monday September 28th I would get a list of:


But in the code above I get the following list:

I did some searching on the internet. I used the suggestion in How can I increment a date by one day in Java?
 
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the problem is in this line.

 
Marshal
Posts: 79019
375
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't mix LocalDate and Calendar. You are right to use LocalDate, so stop using Calendar. Have you been through the Java™ Tutorials about dates? I am pretty sure you can get a date object for “next Monday” or “last Friday”.

They say local date is immutable and show an example with 14th May. I always thought they used 23rd May, which is Duke's Birthday

Try the section called Date Classes for an example with “next Wednesday”.
 
Daan Heuvelbeuk
Ranch Hand
Posts: 89
Netscape MySQL Database Windows XP
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Don't mix LocalDate and Calendar. You are right to use LocalDate, so stop using Calendar.



Righto. Thanks.
reply
    Bookmark Topic Watch Topic
  • New Topic