Originally posted by sarma kiran:
Calenar cal = Calendar.getInstance();
cal.set( Calendar.YEAR, cal.get (Calendar.YEAR) );
cal.set( Calendar.MONTH, cal.get(Calendar.MONTH));
cal.set( Calendar.DATE, cal.get(Calendar.DATE));
Date intialCurrentDate = new Date(cal.getTime().getTime());
cal.setTime(intialCurrentDate);
int monthVal =cal.get(Calendar.MONTH);
int dateVal = cal.get(Calendar.DATE);
int dayofMonth = cal.get(Calendar.DAY_OF_MONTH);
What exactly are you trying to do here? You create a Calendar object (excellent!), but then you set the year, month and day - to the values it already had!
Next you call getTime() which creates a new Date object, but decide to create yet another Date object equal to the one you just created. Then you use that to set the Calendar's date/time again - to the values it already had!
You can remove all of this code except for the first one and last three lines.
That should work just fine, but please please PLEASE don't use 1 and 7 - use Calendar.SUNDAY and Calendar.SATURDAY.
Now all you seem to be missing is getting your Calendar object to point to the last date of the month.
I can think of two ways:
Take the current date and add one month. Set the day of the month to 1 (so it is the first of the next month). Subtract one day.Set the day of the month using Calendar.getActualMaximum. This will return the last day for the current month. [ September 17, 2008: Message edited by: Rob Prime ]