Here you can find the source of calculateEasterDay(int year)
Parameter | Description |
---|---|
year | the given year |
public static Date calculateEasterDay(int year)
//package com.java2s; /*/*from w ww . j a va2s . co m*/ * Utility class for a easy way to handle Date * Copyright (C) 2012 Martin Absmeier, IT Consulting Services * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ import java.util.Calendar; import java.util.Date; public class Main { /** * Calculates the easter day of given year. * * @param year * the given year * @return the calculated easter day */ public static Date calculateEasterDay(int year) { int a = year % 19; int b = year % 4; int c = year % 7; int month = 0; int m = (8 * (year / 100) + 13) / 25 - 2; int s = year / 100 - year / 400 - 2; m = (15 + s - m) % 30; int n = (6 + s) % 7; int d = (m + 19 * a) % 30; if (d == 29) { d = 28; } else if (d == 28 && a >= 11) { d = 27; } int e = (2 * b + 4 * c + 6 * d + n) % 7; int day = 21 + d + e + 1; if (day > 31) { day = day % 31; month = 4; } if (day <= 31) { month = 3; } month++; return createDate(year, month, day); } /** * Creates a <code>java.util.Date</code> <b>without</b> time slice. * * @param year * the given year * @param month * the given month * @param date * the given date * @return the created <code>java.util.Date</code>. */ public static Date createDate(int year, int month, int date) { return createDate(year, month, date, 0, 0, 0); } /** * Creates a <code>java.util.Date</code> <b>with</b> time slice. * * @param year * the given year * @param month * the given month * @param date * the given date * @param hourOfDay * the given hour of day * @param minute * the given minute * @param second * the given second * @return the created <code>java.util.Date</code>. */ public static Date createDate(int year, int month, int date, int hourOfDay, int minute, int second) { Calendar cal = Calendar.getInstance(); cal.set(year, (month - 1), date, hourOfDay, minute, second); return new Date(cal.getTimeInMillis()); } }