如何查看此时间戳是今天,明天还是后天?

qwe*_*nau 9 php date

我想知道如何检查时间戳是今天,明天还是后天.

我有例如:

$timestamp = "1313000474";
Run Code Online (Sandbox Code Playgroud)

如何查看此时间戳是今天,明天还是后天?

例如

if today then echo $output = "today";
if tomorrow then echo $output = "tomorrow";
if the day after tomorrow then echo $output = "dayaftertomorrow";
Run Code Online (Sandbox Code Playgroud)

这该怎么做?

编辑:更正了unix时间戳

先感谢您.

Dan*_*man 25

$timestamp = "1313000474";

$date = date('Y-m-d', $timestamp);
$today = date('Y-m-d');
$tomorrow = date('Y-m-d', strtotime('tomorrow')); 
$day_after_tomorrow = date('Y-m-d', strtotime('tomorrow + 1 day'));

if ($date == $today) {
  echo "today";
} else if ($date == $tomorrow) {
  echo "tomorrow";
} else if ($date == $day_after_tomorrow) {
  echo "dayaftertomorrow";
}
Run Code Online (Sandbox Code Playgroud)

  • 搞什么鬼?IT看起来像复制? (2认同)
  • 真的,伙计?我们不做同样的事情,我没有理由复制你的代码,这在逻辑上是不正确的,并没有产生所需的输出. (2认同)