Date calculation class

https://www.cnblogs.com/woxiaosade/p/11829060.html

https://blog.csdn.net/Dream_Weave/article/details/80487951

1. Year, month, day-->week X

1. Kim Larson: w=(d+2*m+3*(m+1)/5+y+y/4-y/100+y/400)%7 // w:0: week One...and so on

int cal1(int y,int m,int d)
{
    if(m==1||m==2)
        m+=12,y--;
    int w=(d+2*m+3*(m+1)/5+y+y/4-y/100+y/400)%7;
    return ++w;
}

2. Zeiler formula: w=(y+y/4+c/4-2*c+26*(m+1)/10+d-1+7)%7 // w:0: Sunday.. .So on and so forth

int cal2(int y,int m,int d)
{
    if(m==1||m==2)
        m+=12,y--;
    int c=y/100,ty=y%100;
    int w=ty+ty/4+c/4-2*c+26*(m+1)/10+d-1;
    return w%7==0?7:(w+7)%7;
}

Ps: Formula symbol description:
w: 0: Sunday... and so on (the latter +7 is because negative numbers are considered)
c: century-1 (the first two digits of
y ) y: year (the last two digits of y)
m : Month (m>=3 && m<=14, that is, in Zeiler's formula and Kim Larson's formula, January and February of a year should be calculated as the 13th and 14th months of the previous year, such as: January 1st, 2003 --> 13th, 2002)
d: day

 

[]: Represents rounding (here is exactly rounding down), that is, as long as the integer part.

Guess you like

Origin blog.csdn.net/weixin_43871207/article/details/109321001