easter_days

(PHP 4, PHP 5, PHP 7, PHP 8)

easter_days得到指定年份的 3 月 21 日到复活节之间的天数

说明

easter_days(?int $year = null, int $mode = CAL_EASTER_DEFAULT): int

返回指定年份的 3 月 21 日到复活节之间的天数,如果没有指定年份,默认是当年。

此函数可以用来代替 easter_date() 来计算超出 Unix 时间戳范围(比如 1970 年以前或 2037 年以后)的年份的复活节日期。

复活节的日期是由尼西亚议会在公元 325 年确定的为每年春分月圆后的第一个星期日。春分一般是在 3 月 21 日,这就简化为只要计算满月的日期和紧挨的星期日的日期。这里所用的算法是在 532 年由 Dionysius Exiguus 引入。在 1753 年以前用儒略历计算,一个简单的 19 年周期用于追踪月相。在 1753 年之后公历(由 Clavius 和 Lilius 设计,1582 年 10 月由教皇 Gregory 十三世引入,并于 1752 年 9 月进入英国及其当时的殖民地)添加了两个校正因子以使周期更准确。

参数

year

年份为正整数。如果省略或为 null, 默认为本地时间的当前年份。

mode

当设置为 CAL_EASTER_ROMAN 时,允许用公历来计算 1582 年至 1752 年之间的复活节日期。更多有效常量参考 calendar 常量

返回值

根据指定参数 year 而返回 3 月 21 日至复活节的天数。

更新日志

版本 说明
8.0.0 year 现在可为空(nullable)。

示例

示例 #1 easter_days() 示例

<?php

echo easter_days(1999); // 14, i.e. April 4
echo easter_days(1492); // 32, i.e. April 22
echo easter_days(1913); // 2, i.e. March 23

?>

参见

  • easter_date() - 得到指定年份的复活节午夜时的 Unix 时间戳

add a note add a note

User Contributed Notes 2 notes

up
3
p dot rijt at caesar dot nl
8 years ago
This function returns an array of timestamp corresponding to Dutch National holidays. Liberation Day (Bevrijdingsdag) is added as a National holiday once every five years (2000, 2005, 2010, ...).

<?php
function getHolidays($year = null) {
    if (
$year === null) {
       
$year = intval(date('Y'));
    }
   
   
$easterDate  = easter_date($year);
   
$easterDay   = date('j', $easterDate);
   
$easterMonth = date('n', $easterDate);
   
$easterYear   = date('Y', $easterDate);
 
   
$holidays = array(
       
// Nieuwjaarsdag
       
mktime(0, 0, 0, 11$year), 
       
// 1e Kerstdag
       
mktime(0, 0, 0, 12, 25, $year), 
       
// 2e Kerstdag
       
mktime(0, 0, 0, 12, 26, $year)
    );
     
   
// Bevrijdingsdag
   
if (($year % 5) == 0) {
       
$holidays[] = mktime(0, 0, 0, 5, 5, $year); 
    }
   
   
// Koninginnedag (< 2014) of Koningsdag (>= 2014).
    // Verplaats naar zaterdag als het valt op zondag.
   
if ($year <= 2013) { // Koninginnedag <= 2013
       
if (date('w', mktime(0, 0, 0, 4, 30, $year)) == 0) { // Op zondag?
           
$holidays[] = mktime(0, 0, 0, 4, 29, $year);  // Verplaats naar zaterdag
       
} else {
           
$holidays[] = mktime(0, 0, 0, 4, 30, $year);  // Koninginnedag
       
}
    } else {
// Koningsdag > 2014
       
if (date('w', mktime(0, 0, 0, 4, 27, $year)) == 0) { // Op zondag?
           
$holidays[] = mktime(0, 0, 0, 4, 26, $year);  // Verplaats naar zaterdag
       
} else {
           
$holidays[] = mktime(0, 0, 0, 4, 27, $year);  // Koningsdag
       
}
    }
   
   
// Onderstaande dagen hebben een datum afhankelijk van Pasen
    // Goede Vrijdag (= pasen - 2)
   
$holidays[] = strtotime('-2 days', mktime(0, 0, 0, $easterMonth, $easterDay$easterYear));
   
// 1e Paasdag
   
$holidays[] = mktime(0, 0, 0, $easterMonth, $easterDay$easterYear);
   
// 2e Paasdag (= pasen +1)
   
$holidays[] = strtotime('+1 days', mktime(0, 0, 0, $easterMonth, $easterDay$easterYear));
   
// Hemelvaartsdag (= pasen + 39)
   
$holidays[] = strtotime('+39 days', mktime(0, 0, 0, $easterMonth, $easterDay$easterYear));
   
// 1e Pinksterdag (= pasen + 49)
   
$holidays[] = strtotime('+49 days', mktime(0, 0, 0, $easterMonth, $easterDay$easterYear));
   
// 2e Pinksterdag (= pasen + 50)
   
$holidays[] = strtotime('+50 days', mktime(0, 0, 0, $easterMonth, $easterDay$easterYear));

   
sort($holidays);
 
    return
$holidays;
}

$holidays = getHolidays(2014);

foreach (
$holidays as $holiday) {
    echo
date('d-M-Y', $holiday) . '<br>';
}
?>
up
1
ian at eiloart dot com-NOSPAM
22 years ago
Also, be aware that the eastern orthodox churches sometimes have different dates for easter. See, for example <http://webexhibits.org/calendars/calendar-christian-easter.html>. And note that the dates of easter a subject to change,  for example, the churches might some day decide to unify the dates.
To Top