PHP头条
热点:

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


在php中一个有效的时间是从 1970-01-01 07:00:00 – 2038-01-19 03:14:07。
首先一个时间戳中肯定没有小数点.
将 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

方法一:

function isTimeStamp($timestamp) {
    return ctype_digit($timestamp) && $timestamp <= 2147483647;
}
方法二:
  
function is_timestamp($timestamp) {
    if (strtotime(date('m-d-Y H:i:s', $timestamp)) === $timestamp) {
        return $timestamp;
    } else return false;
}

www.phpzy.comtrue/php/23132.htmlTechArticlePHP 中判断一个数字是否是Unix 时间戳 在php中一个有效的时间是从 1970-01-01 07:00:00 – 2038-01-19 03:14:07。 首先一个时间戳中肯定没有小数点. 将 1970-01-01 07:00:00 和 2038-01-19 03:14:07转换成时间...

相关文章

PHP之友评论

今天推荐