Skip to content

Instantly share code, notes, and snippets.

@ChaosJohn
Created April 30, 2024 01:46
Show Gist options
  • Save ChaosJohn/a4f77ebfba100ed296ae5687232d92b6 to your computer and use it in GitHub Desktop.
Save ChaosJohn/a4f77ebfba100ed296ae5687232d92b6 to your computer and use it in GitHub Desktop.
dow() by Tomohiko Sakamoto
// https://www.zhihu.com/question/30262900/answer/2863211053
// Tomohiko Sakamoto 算法,来确定当前日期是星期几
int dow(int y, int m, int d) {
static int t[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4};
y -= m < 3;
return (y + y/4 - y/100 + y/400 + t[m-1] + d) % 7;
}
// 同时,Tomohiko Sakamoto 还发布了另外一个更简洁的版本:
dow(m,d,y) { y-=m<3; return(y+y/4-y/100+y/400+"-bed=pen+mad."[m]+d)%7; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment