我如何计算何日耶稣受难日适逢给予一年?耶稣、受难日

2023-09-10 23:56:33 作者:温柔十方冬春

有没有人有一个好的算法来计算何日耶稣受难日给出的今年下降为输入? preferably在C#。

Does anyone have a good algorithm to calculate what date Good Friday falls on given the year as an input? Preferably in C#.

推荐答案

下面是一个伟大的文章,应该可以帮助你建立你的算法

Here's a great article that should help you build your algorithm

http://www.$c$cproject.com/KB/datetime/christianholidays.aspx

根据这个例子,你应该可以写:

Based on this example, you should be able to write:

DateTime goodFriday = EasterSunday(DateTime.Now.Year).AddDays(-2);

完整的例子:

public static DateTime EasterSunday(int year)
{
    int day = 0;
    int month = 0;

    int g = year % 19;
    int c = year / 100;
    int h = (c - (int)(c / 4) - (int)((8 * c + 13) / 25) + 19 * g + 15) % 30;
    int i = h - (int)(h / 28) * (1 - (int)(h / 28) * (int)(29 / (h + 1)) * (int)((21 - g) / 11));

    day   = i - ((year + (int)(year / 4) + i + 2 - c + (int)(c / 4)) % 7) + 28;
    month = 3;

    if (day > 31)
    {
        month++;
        day -= 31;
    }

    return new DateTime(year, month, day);
}
 
精彩推荐
图片推荐