PHP 计算复活节
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP 计算复活节相关的知识,希望对你有一定的参考价值。
<?php
/*
PHP Easter Calculation Library
Copyright (c) 2008, reusablecode.blogspot.com; some rights reserved.
This work is licensed under the Creative Commons Attribution License. To view
a copy of this license, visit http://creativecommons.org/licenses/by/3.0/ or
send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California
94305, USA.
This function library allows calculation of the following ecclesiastical holidays:
Ash Wednesday, Palm Sunday, Good Friday, Easter, Ascension Day, and Pentecost.
Refer to Wikipedia for information on the purpose of these holidays..
*/
// Determine the date of Easter for a given year.
function dateEaster($someYear)
{
$goldenNumber = fmod($someYear, 19) + 1;
if ($someYear <= 1752)
{
// Julian calendar
$dominicalNumber = fmod($someYear + ($someYear / 4) + 5, 7);
$paschalFullMoon = fmod(3 - (11 * $goldenNumber) - 7, 30);
}
else
{
// Gregorian calendar
$dominicalNumber = fmod($someYear + ($someYear / 4) - ($someYear / 100) + ($someYear / 400), 7);
$solarCorrection = ($someYear - 1600) / 100 - ($someYear - 1600) / 400;
$lunarCorrection = ((($someYear - 1400) / 100) * 8) / 25;
$paschalFullMoon = fmod(3 - 11 * $goldenNumber + $solarCorrection - $lunarCorrection, 30);
}
while ($dominicalNumber < 0)
{
$dominicalNumber += 7;
}
while ($paschalFullMoon < 0)
{
$paschalFullMoon += 30;
}
if ($paschalFullMoon == 29 || ($paschalFullMoon == 28 && $goldenNumber > 11))
{
$paschalFullMoon--;
}
$difference = fmod(4 - $paschalFullMoon - $dominicalNumber, 7);
if ($difference < 0)
{
$difference += 7;
}
$dayEaster = $paschalFullMoon + $difference + 1;
if ($dayEaster < 11)
{
// Easter occurs in March.
$dateEaster = mktime(0, 0, 0, 3, $dayEaster + 21, $someYear);
}
else
{
// Easter occurs in April.
$dateEaster = mktime(0, 0, 0, 4, $dayEaster - 10, $someYear);
}
return $dateEaster;
}
// Determine the date of Good Friday for a given year.
// Requires dateEaster()
function dateGoodFriday($someYear)
{
$easter = getDate(dateEaster($someYear));
return mktime(0, 0, 0, $easter[mon], $easter[mday] - 2, $easter[year]);
}
// Determine the date of Palm Sunday for a given year.
// Requires dateEaster()
function datePalmSunday($someYear)
{
$easter = getDate(dateEaster($someYear));
return mktime(0, 0, 0, $easter[mon], $easter[mday] - 7, $easter[year]);
}
// Determines the date of Ash Wednesday for a given year.
// Requires dateEaster()
function dateAshWednesday($someYear)
{
$easter = getDate(dateEaster($someYear));
return mktime(0, 0, 0, $easter[mon], $easter[mday] - 46, $easter[year]);
}
// Deteremines the date of Ascension Day for a given year.
// Requires dateEaster()
function dateAscensionDay($someYear)
{
$easter = getDate(dateEaster($someYear));
return mktime(0, 0, 0, $easter[mon], $easter[mday] + 39, $easter[year]);
}
// Determines the date of Pentecost for a given year.
// Requires dateEaster()
function datePentecost($someYear)
{
$easter = getDate(dateEaster($someYear));
return mktime(0, 0, 0, $easter[mon], $easter[mday] + 49, $easter[year]);
}
// Unit tests
// $testYear = 2008;
// echo "Ash Wednesday: " . date("j F Y", dateAshWednesday($testYear)) . "<br>";
// echo "Palm Sunday: " . date("j F Y", datePalmSunday($testYear)) . "<br>";
// echo "Good Friday: " . date("j F Y", dateGoodFriday($testYear)) . "<br>";
// echo "Easter: " . date("j F Y", dateEaster($testYear)) . "<br>";
// echo "Ascension Day: " . date("j F Y", dateAscensionDay($testYear)) . "<br>";
// echo "Pentecost: " . date("j F Y", datePentecost($testYear)) . "<br>";
?>
以上是关于PHP 计算复活节的主要内容,如果未能解决你的问题,请参考以下文章