php开发中,如何判断某个字符串是否为时间戳,下面web建站小编给大家简单介绍一下几种不同实现方法!
方法一:利用DateTime类判断
复制代码function is_timestamp($string)
{
$date = DateTime::createFromFormat('U', $string);
return $date && $date->format('U') == $string;
}
- 1
- 2
- 3
- 4
- 5
方法二:利用strtotime()函数
复制代码function is_timestamp($string)
{
return (bool)strtotime($string);
}
- 1
- 2
- 3
- 4
标签: DateTime类, php时间戳, strtotime
上面是“php如何判断字符串是否为时间戳”的全面内容,想了解更多关于 php入门 内容,请继续关注web建站教程。
当前网址:https://m.ipkd.cn/webs_3995.html
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!