【问题标题】:How to compare date formats in php? or how to check the date is in what format?如何比较php中的日期格式?或者如何检查日期是什么格式?
【发布时间】:2013-02-21 07:35:42
【问题描述】:

如何比较php中的日期格式?例如,我必须检查日期是这种格式(21-02-2013) 还是(21/2/13)。请帮忙

【问题讨论】:

    标签: php date-format


    【解决方案1】:

    (21/2/13)

       function testDate( $value )   
     {   
      return preg_match( ''^\d{1,2}/\d{1,2}/\d{4}$'', $value ) )   
     }   
    
     testDate( '21/11/1999' ); // -> true   
     testDate( '3/9/2008' ); // -> true 
    

    适用于(2013 年 2 月 21 日)

    $d = explode("-"  , $date);
    if( !checkdate($d[1], $d[0], $d[2]) )
    echo 'Not a recognised date' ;
    

    【讨论】:

    • 谢谢!让我检查一下。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-21
    • 1970-01-01
    • 1970-01-01
    • 2014-04-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多