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转换成时间戳.php

  1. 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;
    }
    
相关文章
相关标签/搜索