• Post Reply Bookmark Topic Watch Topic
  • New Topic

Printing all days of the week  RSS feed

 
Daan Heuvelbeuk
Ranch Hand
Posts: 85
MySQL Database Netscape Windows XP
  • Mark post as helpful
  • send pies
  • 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?
 
Knute Snortum
Sheriff
Posts: 4276
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the problem is in this line.

 
Campbell Ritchie
Marshal
Posts: 56540
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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: 85
MySQL Database Netscape Windows XP
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!