因为它里面的星期与日期不是一块变化的,你必须加一个判定程序才能对星期进行判定。
我给你个程序,你看一看他的流程就可以了,你自己改一改。
uchar getweek(uchar year,uchar month,uchar day)
{
unsigned char t1=0,t2=1;
unsigned char week=5; //初始化2000-01-01星期六
int y=2000; //处理年(2000开始)
while(t1
if(((y%4==0)&&(y%100!=0))||(y%400==0))week=week+2; //判断是否是闰年,闰年2月是29天 公式:366%7=2
else week++;
week=week%7;
t1++;
y++;
}
while(t2
switch(t2){
case 1:case 3:case 5:case 7:case 8:case 10: case 12:week=week+3;break; //大月天数31%7=3
case 2:if(((y%4==0)&&(y%100!=0))||(y%400==0)) week++;break; //闰月天数,闰年2月是29天 29%7=1
case 4:case 6:case 9:case 11: week=week+2;break; //小月天数30%7=2
}
week=week%7;
t2++;
}
week=week+day; //处理日(从1日开始)
week=week%7;
if(week==0) week=7;
return week; //返回星期
}