• 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
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

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: 7123
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: 76802
366
  • 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.
 
Forget this weirdo. You guys wanna see something really neat? I just have to take off my shoe .... (hint: it's a tiny ad)
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic