Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Needed logic for java date

 
Kartik Tal
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
  • 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"

 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about

 
Neelesh A Korade
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • 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
  • 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"));
 
Neelesh Korade
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you are right. Didn't realize this earlier. Thank you.
 
Kartik Tal
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot that helped me a lot...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic