Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calendar Month Represented Visually

Status
Not open for further replies.

AdamRice32

Programmer
Dec 31, 2001
38
0
0
US
Here's an interesting problem to which I haven't been able to come up with an intelligent solution:

I need to display months of a Calendar in a JSP or the like. What is a good way to get a list of which days are valid for a particular month? And how can I determine which day of the week (sunday to saturday) the 1st of the month lands on?

Thoughts?

Thanks in advance for any ideas,
Adam Rice
 
For the sake of trying to leave you something to do, i am going to outline some of the above things but leave the rest to you :)
Code:
// Step 1, create a calendar object
Calendar cal = new Calendar();
// Step 2, Set it to the desired year/month/date
cal.set(2002,12,1);
// Step 3, Profit...heh :)
// Step 4, Our calendar is initialized to the first day of the month, what day is it?
System.out.println("The first of the month is.... "+cal.get(DAY_OF_WEEK));
// Step 5, get last day of month
System.out.println("The last day of the month is:"+cal.getActualMaximum(DAY_OF_MONTH));

Etc :)
There is actually some rally cool methods to play with with the calendar object, since there are so many differant field types (DAY_OF_WEEK,DAY_OF_MONTH, WEEK_OF_MONTH) you can actually create output based on each month and let a user move forward through it by weeks rather than months, or do strange calculations based on the number of sundays in a month, etc.

As always I will point you to the API to use as a reference, and I hope the above was what you were looking for,
API:
-Tarwn --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
This space has nothing in it, it's all ni your imagination
 
Cool... thanks much. This should definitely do the trick.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top