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

  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;
    }
    

      

 
posted @ 2013-12-28 01:49  乌冬  阅读(10974)  评论(0编辑  收藏  举报