转自:http://blog.cocoabit.com/mo-nian-li-ji-suan-xing-qi-ji-mu-la-er-sen-gong-shi/
#include/*
* 基姆拉尔森计算公式
* W= (d+2*m+3*(m+1)/5+y+y/4-y/100+y/400) mod 7
*/
int week(int y, int m, int d)
{
if (m < 3) {
m += 12;
y--;
}
int w = (d + 2 * m + 3 * (m + 1) / 5 + y + y / 4 - y / 100 + y / 400) % 7;
return w;
}
int main()
{
printf("%d\n", week(2015, 4, 16)); // => 3 星期四
printf("%d\n", week(1989, 2, 3)); // => 4 星期五
return 0;
}
网友评论