unsigned char today_week(unsigned char year,unsigned char month, unsigned char date)
{
unsigned int doy = 0;
unsigned char i,j;
unsigned char temp = 12;
for(j=0;j {
if(is_leap(j))
doy += 365;
else
doy += 366;
}
for(i=1;i {
if(i==1)
doy += 31;
else if(i==2)
{
if(is_leap(year))
doy += 28;
else
doy += 29;
}
else if(i==3)
doy += 31;
else if(i==4)
doy += 30;
else if(i==5)
doy += 31;
else if(i==6)
doy += 30;
else if(i==7)
doy += 31;
else if(i==8)
doy += 31;
else if(i==9)
doy += 30;
else if(i==10)
doy += 31;
else if(i==11)
doy += 30;
else if(i==12)
doy += 31;
}
doy += date;
return (doy+5) % 7;
}
unsigned char is_leap(unsigned char year) //check for leap year
{
unsigned int temp = 2000;
temp = temp + year;
if (!(temp%100))
return (char)(temp%400);
else
return (char)(temp%4);
}
其实程序本身隐含着一个参考日期对应的星期,那就是2000年1月1日,对应周六,计算这以后的日期对应的星期其实就是累加的方法计算的.
阅读(1865) | 评论(0) | 转发(0) |