• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

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: 79965
396
  • 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.
 
Watchya got in that poodle gun? Anything for me? Or this tiny ad?
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic