Calculate several algorithms of the week

zhaozj2021-02-16  132

Calculate several algorithms of the week

http://blog.9cbs.net/yice800/archive/2004/08/09/68997.aspx

Recently, some people saw that someone asked the week algorithm, especially organized, these algorithms were searching from online, and the implementation of the algorithm was written in the project. I hope to be helpful.

One: Common formula W = [Y-1] [(Y-1) / 4] - [(Y-1) / 100] [(Y-1) / 400] D

Y Y is the number of years, D is the cumulative day of this day in this year, that is, this day is the first day this year.

2: Zeller formula

W = Y [Y / 4] [C / 4] -2C [26 (M 1) / 10] D-1

The symbols in the formula are as follows, W: Week; C: Century; Y: Year (two digits); M: Month (M is greater than or equal to 3, less than or equal to 14, in the Caile formula, 1, 2 The month should be considered as a previous year to calculate. For example, January 1, 2003 is considered to be calculated on March 1, 2002); D: Japan; [] Represents Fix, ie .

The Zeller formula greatly reduces the computational complexity compared to the general general calculation formula.

Three: Improvements to the Zeller formula

Author: Cong Feng think in terms compared to other common generic formula, Zeller (Zeller) formula greatly reduces the computational complexity. However, the general-purpose calculation formula given by the author seems to be more simple (including the operation process). The formula is now listed below: w = [Y / 4] R (Y / 7) -2R (C / 4) m ' D

The symbols in the formula are as follows, and R () represents the payment, that is, as long as the remaining number; M 'is the correction number of M, it is now given from 1 to December 1' to 12 'below: (1', 10 ') ) = 6; (2 ', 3') = 2; (4 ', 7') = 5; 5 '= 0; 6' = 3; 8 '= 1; (9', 12 ') = 4 (Note: In the formula given by the author, Y is 1 '= 5; 2' = 1). Other symbols are the same as the meaning of the Zeller formula.

Four: Kelason Calculation Formula

The name of this formula is named, haha, I hope everyone should not see it.

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 the date, and m represents the number of months, y indicates the number of years.

Note: There is a place different from other formulas in the formula:

Despect in January and February as the last year of the last year of the last year, the example: If it is 2004-10, it is converted to: 2003-13-10 to enter the formula calculation.

to sum up:

These algorithms have characteristics, as for the specific calculation process of the formula, because the reason is not listed here, if necessary, leave the email address, I will send it to you. Posted on August 09, 2004 9:59 AM

转载请注明原文地址:https://www.9cbs.com/read-7735.html

New Post(0)