import java.time.LocalDate; public class Easter { public static void main(String[] args) { int year = 2008; LocalDate easterDate = calculateEasterDate(year); System.out.println("复活节日期:" + easterDate); } public static LocalDate calculateEasterDate(int year) { int goldenNumber = (year % 19) + 1; int century = year / 100 + 1; int skippedLeapYears = (3 * century / 4) - 12; int correctionFactor = ((8 * century + 5) / 25) - 5; int sundayIndex = (5 * year / 4) - skippedLeapYears - 10; int epact = (11 * goldenNumber + 20 + correctionFactor - skippedLeapYears) % 30; if ((epact == 25 && goldenNumber > 11) || epact == 24) { epact++; } int day = 44 - epact; if (day < 21) { day += 30; } day += 7 - ((sundayIndex + day) % 7); if (day > 31) { return LocalDate.of(year, 4, day - 31); } else { return LocalDate.of(year, 3, day); } } }
复活节_java
最新推荐文章于 2024-07-13 13:55:40 发布