一年如何计算耶稣受难日的日期? [英] How can I calculate what date Good Friday falls on, given a year?
本文介绍了一年如何计算耶稣受难日的日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
解决方案
这是一篇伟大的文章,应该可以帮助您构建算法。
http://www.codeproject.com/KB/datetime/christianholidays。 aspx
根据这个例子,你应该可以写:
DateTime goodFriday = EasterSunday(DateTime.Now.Year).AddDays(-2);
完整示例:
public static DateTime EasterSunday(int year)
{
int day = 0;
int month = 0;
int g =年%19;
int c = year / 100;
int h =(c - (int)(c / 4) - (int)((8 * c + 13)/ 25)+ 19 * g + 15)%30; $($)$($)$($)$($)$($) g)/ 11));
day = i - ((年+(int)(年/ 4)+ i + 2 - c +(int)(c / 4))%7)+ 28;
month = 3;
if(day> 31)
{
month ++;
day - = 31;
}
返回新的DateTime(年,月,日);
}
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.codeproject.com/KB/datetime/christianholidays.aspx
Based on this example, you should be able to write:
DateTime goodFriday = EasterSunday(DateTime.Now.Year).AddDays(-2);
Full Example:
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);
}
这篇关于一年如何计算耶稣受难日的日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文