原理不谈,直接百度“蔡勒公式”,本文直接谈代码实现(c++)
传入年月日,返回的就是星期几了
int Day(int year, int month, int day){
int ret = 0;
int c, y, m, d;
if(month <= 2){
c = ( year - 1 ) / 100;
y = ( year - 1 ) % 100;
m = month + 12;
d = day;
}
else{
c = year / 100;
y = year % 100;
m = month;
d = day;
}
ret = y + y / 4 + c / 4 - 2 * c + 26 * ( m + 1 ) / 10 + d - 1;
ret = ret >= 0 ? ( ret % 7 ) : ( ret % 7 + 7 );
if(ret == 0){
ret = 7;
}
return ret;
}
over