复活节(Easter),是纪念耶稣基督复活的节日,在西方教会传统里,春分之后第一次满月之后的第一个星期日即为复活节。
下面是一个简单的计算复活节的算法,仅供参考!
1、设要求的那一年是Y年,从Y减去1900,其差记为N。
2、用19作除数去除N,余数记为A。
3、用4作除数去除N,不管余数,把商记为Q。
4、用19去除7A+1,把商记为B,不管余数。
5、用29去除11A+4-B,余数记为M。
6、用7去除N+Q+31-M,余数记为W。
7、计算25-M-W。
得出答数即可定出复活节的日期。若为正数,月份为4月,如为负数,月份为3月。若为0,则为3月31日。
代码实现如下:
public static boolean GetEasterDay(MutableInt year, MutableInt month,
MutableInt day) {
int N = year.intValue() - 1900;
int A = N % 19;
int Q = N / 4;
int B = (7 * A + 1) / 19;
int M = (11 * A + 4 - B) % 29;
int W = (N + Q + 31 - M) % 7;
int result = 25 - M - W;
if (result == 0) {
month.setValue(3);
day.setValue(31);
} else if (result > 0) {
month.setValue(4);
day.setValue(result);
} else {
month.setValue(3);
day.setValue(31 + result);
}
return true;
}