简介
该公式用于计算日期
C++实现
int getWeek(int y, int m, int d) {
if (m == 1 || m == 2) {
m += 12;
y--;
}
int week = (d +1 + 2 * m + 3 * (m + 1) / 5 + y + y / 4 - y / 100 + y / 400) % 7;
return week;
}
python实现
## 要注意对公示中的除法,及时取整
def getWeek(y, m, d):
if (m == 1 or m == 2):
m = m + 12
y = y -1
return int((d + 2 * m + int(3 * (m + 1) / 5) + y + int(y / 4) - int(y / 100) + int(y / 400)) % 7)