aspose file tools*
The moose likes Java in General and the fly likes Needed logic for java date Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Needed logic for java date" Watch "Needed logic for java date" New topic
Author

Needed logic for java date

Kartik Talasu
Ranch Hand

Joined: Aug 21, 2009
Posts: 98
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

Joined: Feb 23, 2009
Posts: 1183
How about



JDBCSupport - An easy to use, light-weight JDBC framework -
Neelesh A Korade
Greenhorn

Joined: Jun 07, 2007
Posts: 26
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

Joined: Feb 23, 2009
Posts: 1183
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

Joined: Dec 01, 2006
Posts: 2
Yes, you are right. Didn't realize this earlier. Thank you.
Kartik Talasu
Ranch Hand

Joined: Aug 21, 2009
Posts: 98
Thanks a lot that helped me a lot...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Needed logic for java date
 
Similar Threads
problem formatting date string
is this not suppose to give me date of the week?
Convert the String to date format
Need to change Calendar to dd/mm/yyyy format
weird java dates!!!!