PHP checkdate()函数 (PHP checkdate() function)
checkdate() function is used to check the valid Gregorian dates. It accepts the date and returns Boolean values (True/False) based on the date values.
checkdate()函数用于检查有效的公历日期。 它接受日期,并根据日期值返回布尔值(真/假)。
Syntax:
句法:
checkdate(month,day,year);
Parameter(s):
参数:
month – It specifies the month in the numbers starting from 1 to 12.
month –以1到12之间的数字指定月份。
day – It specifies the day in the numbers starting from 1 to 31.
日期 –以1到31之间的数字指定日期。
year – It specifies the year in the numbers from 1 to 32767.
year –以1到32767之间的数字指定年份。
Return value:
返回值:
It returns "TRUE" – if the date is valid, else it returns "FALSE".
它返回“ TRUE” –如果日期有效,则返回“ FALSE”。
Example: PHP code to check whether given date is valid Gregorian date
示例:检查给定日期是否有效的公历日期PHP代码
<?php
var_dump(checkdate(12, 31, 2019)); //valid
var_dump(checkdate(12, 31, -2018)); //invalid
var_dump(checkdate(2, 29, 2019)); //invalid
var_dump(checkdate(2, 29, 2020)); //valid
//checking through conditions
if (checkdate(12, 31, 2019)) echo "Valid\n";
else echo "Invalid\n";
if (checkdate(12, 31, -2018)) echo "Valid\n";
else echo "Invalid\n";
if (checkdate(2, 29, 2019)) echo "Valid\n";
else echo "Invalid\n";
if (checkdate(2, 29, 2020)) echo "Valid\n";
else echo "Invalid\n";
?>
Output
输出量
bool(true)
bool(false)
bool(false)
bool(true)
Valid
Invalid
Invalid
Valid
Reference: PHP checkdate() function
翻译自: https://www.includehelp.com/php/checkdate-function-with-example.aspx