source Good Search encyclopedia: http://baike.haosou.com/doc/1048888-1109421.htmlCaille (Zeller) formula, is a calculation of the week formula, casually to a date, you can use this formula to calculate the day of the week. formula W = [C/4]-2C + y + [Y/4] + [* (m+1)/5] + d-1(or: w=y+[y/4]+[c/4]-2c+[26 (m+1)/10]+d-1)to calculate the date on or before October 4, 1582, the formula is w=y+[y/4]+[c/4]-2c+[13 (m+1)/5]+d+2
as of September 3, 1572:
after September 3, 1572: W = (d + 2*m+3* (m+1)/5+y+y/4-y/100+y/400)%7;
September 3, 1572 before: W = (d+2*m+3* (m+1)/5+y+y/4+5)% 7;Symbolic MeaningW: Week; W 7 modulo: 0-Sunday, 1-Monday, 2-Tuesday, 3-Wednesday, 4-Thursday, 5-Friday, 6-Saturday
C: Century minus 1 (the first two digits of the year)
y: Year (the latter two digits)
m: month (m greater than or equal to 3, less than or equal to 14, that is, in the Caille formula, the December of the year is considered as the last year of 13, 1 April to calculate, such as January 1, 2003 to be considered as 2002 1 March 1 to calculate)
D: Day
[] represents rounding, that is, as long as the integer part.
The following is the day of the 100 anniversary anniversary of the founding of the People's Republic of China (October 1, 2049), as follows:
w=y+[y/4]+[c/4]-2c+[26 (m+1)/10]+d-1
=49+[49/4]+[20/4]-2x20+[26x (10+1)/10]+1-1
=49+[12.25]+5-40+[28.6]
=49+12+5-40+28
= 54 (divided by 7 + 5)
October 1, 2049 (100 Anniversary National Day) is Friday.
Another example is the calculation of April 4, 2006, the process is as follows:
w=y+[y/4]+[c/4]-2c+[26 (m+1)/10]+d-1
=6+[6/4]+[20/4]-2*20+[26* (4+1)/10]+4-1
=-12 (divided by more than 7 5, pay attention to the negative number of the modulo operation!) It should actually be Tuesday instead of Friday)
w= ( -12%7+7)%7=2;Scope of applicationHowever, the Caille formula is only suitable for 1582 (China's Ming Dynasty Wanli 10 years) after October 15. Pope Gregory 13 organized a group of astronomers in 1582 to revise the Julian calendar according to the data calculated by Copernicus heliocentric. 10 days between 14th and October 5, 1582 will be revoked, following October 4 for October 15.
Later, the new calendar was called the Gregorian calendar, which is the universal calendar of today's world, referred to as Gregorian calendar. Calculate CodeThe calculation code after 1582.10.4 is as follows:
1#include <stdio.h>2 intMain ()3 {4 intYear , month, day;5 while(SCANF ("%d%d%d", &year, &month, &day)! =EOF) {6 intI, J, K;7 intc = year/ -;8 inty = year-c * -;9 intWeek =int(c/4) -2* C +int(Y + y/4) +int( -* (Month +1)/5) + Day-1;Ten while(Week <0) One { AWeek + =7; - } -Week%=7; the Switch(week) - { - Case 1: printf ("monday\n"); Break; - Case 2: printf ("tuesday\n"); Break; + Case 3: printf ("wednesday\n"); Break; - Case 4: printf ("thursday\n"); Break; + Case 5: printf ("friday\n"); Break; A Case 6: printf ("saturday\n"); Break; at Case 0: printf ("sunday\n"); Break; - } - } - return 0; -}
Other formulasthe formula for calculating the number of days of the week has the following formula:
⒈week= (Day + 2*month + * * (month+1)/5 + year + YEAR/4-year/100 + year/400)% 7
(where year is a 4-digit number, such as 2009.) The "%" number is the equation except 7 to take the remainder)
Note:
I. The formula is to treat January and February respectively as the 1 March and 1 April of the previous year.
For example: January 4, 2008 to be replaced by March 4, 2007 into the formula.
II. This formula corresponds to the Caille equation a little different: "0" for the Week 1, ..., "6" for Sunday.
improvements:
the formula May and Caille formulas are more complex, but there are improvements: for the century this concept is not referenced, directly is the calculation of the number of years (4 digits)! It is no longer necessary to separate the century from the number of years (the last two).
⒉ Kimlarsson Calculation formula
w= (d+2*m+3* (m+1)/5+y+y/4-y/100+y/400) MoD 7 in the formula D represents the number of days in a date +1,m represents the number of months, and Y represents the number of years.
Note: To change the formula above a formula needs to see January and February as the January or March and January or April of the previous year, not the same as just substituting the formula
d is the date plus 1. So the result of the calculation is the actual week, do not need to add 1, that is: "1" for the Week 1, ..., "7" for Sunday.
Example: If it is 2004-1-10, it will be converted into: 2003-13-10 to the formula calculation.
Example: 2006-10-17 when calculating: d=18,m=10,y=2006.
⒊ (year + year/4+/400-year/100-year base + month base + day)/7= ... Days of the week note: The formula of the score are all year base, common year 1, leap years 2, month base, 1, Common year: January 0, 3, March 3, April 6, May 1, June 4, July 0, August 3, September 5, October 0, November 3, December 5. 2. Leap year: January 0, 3, March 4, April 0, May 2, June 5, July 0, August 3, September 6, October 1, November 4, December 6. If: October 1, 1949 is the day of the week? (1949+1949/4+1949/400-1949/100-1+0+1)/7= (1949+487+4-19-1+0+1)/7=345 ... 6 that day is Saturday.
The so-called monthly base, is the number of days before the sum of 7, such as the January base, the number of days before the sum of the total number of 7 is 0, then the base of the month is 0, such as April (leap year) base, the sum of the preceding three months of the total number of days: (31+29+31)/7=91/7 ... 0 in order to simplify the operation, first take 7 of each month, then add, then take 7 more: (3+1+3)/7 ... 0, that is, the April base is 0, in order to speed up the calculation, usually common year and leap years in the month base table, directly to calculate. Month base, 1, Common year: January 0, 3, March 3, April 6, May 1, June 4, July 0, August 3, September 5, October 0, November 3, December 5. 2. Leap year: January 0, 3, March 4, April 0, May 2, June 5, July 0, August 3, September 6, October 1, November 4, December 6.
Caille (Zeller) formula