PHP | easter_date()函数

这个 复活节 函数是PHP中的一个内置函数,它返回作为参数传递的年份中的复活节日期。当没有参数作为参数传递时,将当前年份作为默认年份。

null

语法:

easter_date( $year )

参数: 该函数接受一个可选参数 美元一年 指定要返回复活节日期的年份。年份只能是1970年到2037年之间的数字。当年份超出范围时,它会返回一条错误消息。

返回值: 它返回参数中经过的给定年份的复活节日期。如果未传递任何参数,则返回当前年份的复活节日期。

例如:

Input : 2018
Output : Apr-01-2018

Input : 2017
Output : Apr-16-2017

下面的程序演示了easter_date()函数:

项目1: 当不传递任何参数时,程序将演示该函数。

<?php
// PHP program to demonstrate the
// working of easter_date() function
// when no parameter is passed
// prints the date of Easter of year 2018
// when no parameter is passed
echo date ( "M-d-Y" , easter_date()), "" ;
// current year to verify
$year = 2018;
echo date ( "M-d-Y" , easter_date( $year ));
?>


输出:

Apr-01-2018
Apr-01-2018

项目2: 当传递参数时,程序将演示该函数。

<?php
// PHP program to demonstrate the
// working of easter_date() function
// when parameter is passed
$year = 2017;
echo date ( "M-d-Y" , easter_date( $year )), "" ;
$year = 2010;
echo date ( "M-d-Y" , easter_date( $year )), "" ;
$year = 2000;
echo date ( "M-d-Y" , easter_date( $year ));
?>


输出:

Apr-16-2017
Apr-04-2010
Apr-23-2000

方案3: 当参数超出范围时,程序将演示该函数。

<?php
// PHP program to demonstrate the
// working of easter_date() function
// when parameter is out of range
$year = 2050;
echo date ( "M-d-Y" , easter_date( $year )), "" ;
?>


输出:

PHP Warning:  easter_date(): This function is only valid 
for years between 1970 and 2037 inclusive in
/home/df540ecbab7094243e7668326260e785.php on line 8

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

© 版权声明
THE END
喜欢就支持一下吧
点赞15 分享