php判断时间戳是否为今天实例讲解

来自:网络
时间:2023-01-03
阅读:

 本教程操作环境:windows7系统、PHP7.1版、DELL G3电脑

php判断指定时间戳是不是今天的方法

实现思想:

  • 使用date()格式化今天的日期,将其转为“年月日”格式
  • 使用date()格式化指定时间戳,将其转为“年月日”格式
  • 使用“==”运算符判断是否相等,如果相等则指定时间戳是今天

实现代码:

<?php
header('content-type:text/html;charset=utf-8');
$timestamp = time();  // 获取一个时间戳
if(date('Ymd', $timestamp) == date('Ymd')) {
    echo '是今天';  
}else{
    echo '不是今天';  
}
?>

输出结果

是今天

返回顶部
顶部