• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Calendar problem

 
Soumya Ghosh
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot.
 
Soumya Ghosh
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21518
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Soumya Ghosh
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21518
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic