Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Needed logic for java date

 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

Am having a calendar control for my page where am getting date in dd/mm/yyyy format which is taken as a string.
And am converting that string to DateFormat and then to Calendar. Below is the code which I have used



1) I need a logic in such a way that if I select a date it has to check the day and if its not monday it has to get the Monday of that particular week.
For example like if he selected "26/8/2009" the day will be Wednesday, I need a logic where it gives "24/8/2009" as it is monday of that particular week.
2) And next is after getting "24/8/2009" , I need one more logic like it has to get date of next four weeks that is "21/9/2009"

 
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How about

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Might be trickier than this.

If the initial date is a SUNDAY, for example "30/8/2009", this will return 31/8/2009. Not sure if that is what is expected. If 24/8/2009 is the desired result, a bit complicated logic can be written.
 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is because the US week starts on sunday.
You could change this by passing a locale with a country that's week starts on Monday, such as Germany.

Calendar cal = Calendar.getInstance(new Locale("DE"));
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, you are right. Didn't realize this earlier. Thank you.
 
Kartik Tal
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot that helped me a lot...
 
crispy bacon. crispy tiny ad:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic