PHP--判断是否为时间戳

PHP 中判断一个数字是否是Unix 时间戳

在php中一个有效的时间是从 1970-01-01 07:00:00 – 2038-01-19 03:14:07. 这个的http://php.net/manual/en/function.strtotime.php
首先一个时间戳中肯定没有小数点.
将 1970-01-01 07:00:00 和 2038-01-19 03:14:07转换成时间戳.

echo strtotime('2038-01-19 03:14:07'); // 2147454847
echo strtotime('1970-01-01 07:00:00'); // 0
$valid = ctype_digit($str) && $str <= 2147483647;
var_dump($valid);
  
//method 2
function is_timestamp($timestamp) {
    if(strtotime(date('m-d-Y H:i:s',$timestamp)) === $timestamp) {
        return $timestamp;
    } else return false;
}

原文:https://www.cnblogs.com/itime/p/3494986.html

猜你喜欢

转载自blog.csdn.net/cplvfx/article/details/84939282