php判断日期格式是否正确的小例子
发布时间:2017-09-10 编辑:jiaochengji.com
分享一个php判断日期格式的实例代码,很简单,主要使用strtotime函数进行日期的判断,有需要的朋友参考下。
例子,php判断日期格式。
代码:
复制代码 代码示例:
<?php
/*
* 方法 isDate
* 功能 判断日期格式是否正确
* 参数 $str 日期字符串
$format 日期格式
* 返回 无
*/
function is_Date($str,$format='Y-m-d'){
$unixTime_1=strtotime($str);
if(!is_numeric($unixTime_1)) return false; //如果不是数字格式,则直接返回
$checkDate=date($format,$unixTime_1);
$unixTime_2=strtotime($checkDate);
if($unixTime_1==$unixTime_2){
return true;
}else{
return false;
}
}
/*
* 方法 isDate
* 功能 判断日期格式是否正确
* 参数 $str 日期字符串
$format 日期格式
* 返回 无
*/
function is_Date($str,$format='Y-m-d'){
$unixTime_1=strtotime($str);
if(!is_numeric($unixTime_1)) return false; //如果不是数字格式,则直接返回
$checkDate=date($format,$unixTime_1);
$unixTime_2=strtotime($checkDate);
if($unixTime_1==$unixTime_2){
return true;
}else{
return false;
}
}
注意:
以上判断方法不是非常严格,对于 2012-03-00 或 2012-02-31 这种格式的日期也会返回 true。
您可能感兴趣的文章:
php判断日期格式是否正确的小例子
JavaScript 判断日期格式是否正确的代码一例
JavaScript检查日期格式正确与否的代码
php验证判断一个日期的格式是否正确
php日期函数的简单示例代码
php mysql日期操作的小例子
php 正则验证日期时间格式实例代码
SQLite函数整理
php获取当前日期和时间详解
PHP学习之校验日期格式合法性?(使用strtotime()和date())
[关闭]