d.set(Calendar.DAY_OF_MONTH,1)我不明白
public static void main(String [] args)
{
GregorianCalendar d=new GregorianCalendar();
int today=d.get(Calendar.DAY_OF_MONTH);
int month=d.get(Calendar.MONTH);
d.set(Calendar.DAY_OF_MONTH,1);//这条语句是把当前的日期设置为这个月的第一天,我不明白,如果说今天是19号,那1-18号怎么算出来?因为下面有一条语句是使日期向后加的.
int weekDay=d.get(Calendar.DAY_OF_WEEK);
System.out.println( "Sun Mon Tue Wed Thu Fri Sat ");
for(int i=Calendar.SUNDAY;i <weekDay;i++)
System.out.print( " ");
do
{
int day=d.get(Calendar.DAY_OF_MONTH);
System.out.printf( "%3d ",day);
if(day==today)
System.out.print( "* ");
else
System.out.print( " " );
if(weekDay==Calendar.SATURDAY)
System.out.println();
d.add(Calendar.DAY_OF_MONTH,1);//这条语句就是使日期向后加
weekDay=d.get(Calendar.DAY_OF_WEEK);
}while(d.get(Calendar.MONTH)==month);
if(weekDay!=Calendar.SUNDAY)
System.out.println();