wood burning stoves 2.0*
The moose likes Java in General and the fly likes Calendar problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Calendar problem" Watch "Calendar problem" New topic
Author

Calendar problem

Soumya Ghosh
Greenhorn

Joined: Dec 31, 2006
Posts: 26
I have a question regarding the use of Calendar.

User will give year (e.g 2006,2007, etc.) as input. I have to find out "all dates" of the "friday,saturday and sunday" of "every month" through out the year. Then I have to display thaose as result.
Not only the first friday,saturday,sunday date.
How can I do that? Can anyone please help me for solving this problem?
Can any one please give me any hint by sample program code?

Thanks
John Bartlett
Ranch Hand

Joined: Jan 25, 2006
Posts: 116
Hi,

This is what i did previously,




This just uses two passed in dates for the date ranges and then uses a while loop to go through that range searching for Fridays and then storing the date for every friday found. Also it has to increment the date.

John
[ March 02, 2007: Message edited by: John Bartlett ]
Soumya Ghosh
Greenhorn

Joined: Dec 31, 2006
Posts: 26
Thanks a lot.
Soumya Ghosh
Greenhorn

Joined: Dec 31, 2006
Posts: 26
Hi,
thanks for giving idea for pulling all fridays within specified date ranges.

but, I have no provision of specifying two dates such as start date and end date.
User will give only YEAR as input. And depending on that year, I have to list all Friday dates,Saturday dates and sunday dates of that corresponding year and for all 12 months.

Please help me by providing a sample code.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18532
    
  40

Originally posted by Soumya Ghosh:
Hi,
thanks for giving idea for pulling all fridays within specified date ranges.

but, I have no provision of specifying two dates such as start date and end date.
User will give only YEAR as input. And depending on that year, I have to list all Friday dates,Saturday dates and sunday dates of that corresponding year and for all 12 months.

Please help me by providing a sample code.


Hate to point out the real obvious... but...

(1) Given a year as the input, isn't the start date January 1st, of that year, and the end date December 31st, of that year?

(2) Given the example, that only checks for Fridays, can't you add a check for Saturday and Sunday too?

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Soumya Ghosh
Greenhorn

Joined: Dec 31, 2006
Posts: 26
Hi,
Thanks for help.
But I can't understand following line of code-------
for (String friday : fridays)

What does it mean?Can you please clarify me? It's new to me.

Thanks
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18532
    
  40

Originally posted by Soumya Ghosh:
Hi,
Thanks for help.
But I can't understand following line of code-------
for (String friday : fridays)

What does it mean?Can you please clarify me? It's new to me.

Thanks


It's the new "foreach" loop that was added with Java 5.0.

Basically, it is just syntactic sugar. The loop...



just compiles to...



Personally, I don't use it myself. Mainly because I have been working in Java for so long, the standard for-loop is now in "muscle memory" for me. The other issue is that the iterator is not in scope, so you can't remove items from the collection correctly.

Henry
Soumya Ghosh
Greenhorn

Joined: Dec 31, 2006
Posts: 26
Thanks a lot.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Calendar problem
 
Similar Threads
Get current week date
Prisoner's doubt
Question regarding the use of Calendar
Question regarding Calendar in Java
What is the difference between DAY_OF_WEEK and DAY_OF_WEEK_IN_MONTH.?