php判断是否为时间戳

 
 判断值是否为时间戳
function is_timestamp($timestamp) {
if(strtotime(date('m-d-Y H:i:s',$timestamp)) === $timestamp) {
return $timestamp;
} else
return false;
}
 
逻辑:
使用strtotime()函数 :将任何字符串的日期时间描述解析为 Unix 时间戳     详解:http://php.net/manual/zh/function.strtotime.php
将标准的时间转换为时间戳 ,然后跟传入的值进行比较
如果是时间戳返回改该值
否则返回false
 
 
 
这个函数我也忘记是从哪复制的了- -

猜你喜欢

转载自www.cnblogs.com/wenbino/p/10523750.html