Calculate the date of Easter Sunday

后端 未结 6 606
半阙折子戏
半阙折子戏 2020-12-11 16:32

Write a program to compute the date of Easter Sunday. Easter Sunday is the first Sunday after the first full moon of spring. Use the algorithm invented by the mathematician

6条回答
  •  既然无缘
    2020-12-11 16:50

    /**
     * Orthodox easter formula, invented back in 1800 by famous Carl Friedrich Gauss.
     */
    public static LocalDate getEasterSundayDate(int year) {
        int a = year % 19,
                b = year / 100,
                c = year % 100,
                d = b / 4,
                e = b % 4,
                g = (8 * b + 13) / 25,
                h = (19 * a + b - d - g + 15) % 30,
                j = c / 4,
                k = c % 4,
                m = (a + 11 * h) / 319,
                r = (2 * e + 2 * j - k - h + m + 32) % 7,
                month = (h - m + r + 90) / 25,
                day = (h - m + r + month + 19) % 32;
    
        return LocalDate.of( year, month, day );
    }
    

提交回复
热议问题