PHP Easter_days()函数用法介绍

2021年3月16日16:31:15 发表评论 895 次浏览

Easter_days()函数是PHP中的一个内置函数, 该函数返回3月21日之后(即给定年份中的复活节天)之后的天数。如果未指定年份, 则将当前年份作为默认值。

语法如下:

easter_days( $year, $method )

参数:该函数接受两个可选参数, 如上所示和以下说明:

  1. 年此参数指定年份。如果未传递任何参数, 则将当前年份作为默认值。
  2. 方法–此参数使你可以基于其他日历来计算复活节日期。如果$方法设置为CAL_EASTER_ROMAN, 它使用1582年至1752年之间的公历。

返回值:该函数返回给定年份中的3月21日之后的天数。当没有年用作参数传递当前年份作为默认年份, 并返回当年3月21日之后的天数。

例子:

Input :  $year = 2018
Output : 11

Input : $year = 2017
Output : 26  

Input: $year = 2015 $method = CAL_EASTER_ROMAN
Output : 15

下面的程序说明了Easter_days()函数的用法:

程序1:下面的程序说明了不传递任何参数时Easter_days()函数的工作方式。

<?php
// PHP program to demonstrate the 
// easter_days() function 
// when no parameter is passed 
  
echo easter_days(), "\n" ;  
  
// verified by passing current year
$year = 2018; 
echo easter_days( $year );  
?>

输出如下:

11
11

程式2:以下程序说明了当以下情况时Easter_days()函数的工作方式:年参数传递

<?php
// PHP program to demonstrate the 
// easter_days() function 
// when $year parameter is passed 
  
  
$year = 2015; 
  
// no of days for Easter after march 21 of year 2015
echo easter_days( $year ), "\n" ;  
  
  
// the Easter date of year 2015
echo date ( "M-d-Y" , easter_date( $year ));     
?>

输出如下:

15
Apr-05-2015

程式3:下面的程序说明了同时传递两个参数时Easter_days()函数的工作方式。

<?php
// PHP program to demonstrate the 
// easter_days() function 
// when both parameters are passed 
  
  
$year = 2014; 
  
// no of days for Easter after march 21 of year 2014 
// of Gregorian Calendar
echo easter_days( $year , CAL_EASTER_ROMAN), "\n" ;  
?>

输出如下:

30

参考: http://php.net/manual/en/function.easter-days.php


木子山

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: