zoukankan      html  css  js  c++  java
  • php checkdate()函数检验日期的有效性

    checkdate()函数语法:

    checkdate()函数是检查日期的有效性,它的语法如下:大理石平台检定规程

    1

    checkdate (month , day ,year )

    语法详解:

    如果给出的日期有效则返回 TRUE,否则返回 FALSE。

    它有三个参数:其中 month 的有效值为1~12;day的有效值为当月的最大天数,如1月为31天,2月为29天(闰年);year 的有效值从1~366.

    checkdate()函数实例

    我们使用checkdate()函数来检查一个正确的日期,一个错误的日期,代码如下:

    首先检查对的日期:

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    11

    <?php

    header("Content-type:text/html;charset=utf-8");    //设置编码

     

    $year=2017;       //年份

    $month=4;

    $day=30;

     

    var_dump(checkdate($year,$month,$day));

     

     

    ?>

    运行结果如下图:

    下面我们再用checkdate()函数来检查一个错误的日期,我们看上面的实例知道4月份有30天,我们现在将30改为31天,代码如下:

    1

    2

    3

    4

    5

    6

    7

    8

    9

    <?php

    header("Content-type:text/html;charset=utf-8");    //设置编码

    $year=2017;       //年份

    $month=4;

    $day=31;

     

    var_dump(checkdate($month,$day,$year));

     

    ?>

    运行结果如下图:

    也可以直接在checkdate()函数里面写日期

    1

    2

    3

    4

    5

    6

    <?php

    header("Content-type:text/html;charset=utf-8");    //设置编码

     

    var_dump(checkdate(12,4,2017));

     

    ?>

  • 相关阅读:
    linux命令之------touch命令
    linux命令之------rm命令
    linux命令之------Mv命令
    linux命令之------Less命令
    linux命令之------More命令
    linux命令之------Find命令
    linux命令之------Chown命令
    linux命令之------Chmod命令
    linux命令之------Cat命令
    linux命令之------Wc命令(word count)
  • 原文地址:https://www.cnblogs.com/furuihua/p/12120363.html
Copyright © 2011-2022 走看看