如何检查这个时间戳是今天、明天还是后天


How to make a check if this timestamp is today,tomorrow or the day after tomorrow?

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

例如:
$timestamp = "1313000474";

如何检查这个时间戳是今天,明天还是后天?

if today then echo $output = "today";
if tomorrow then echo $output = "tomorrow";
if the day after tomorrow then echo $output = "dayaftertomorrow";

如何做到这一点?

EDIT: corrected unix timestamp

提前感谢。

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

保持代码整洁…

$timestamp = "1313000474";
// Description demonstrate proposes only...
$compare_dates = array(
    'today' => 'today!!',
    'tomorrow' => 'Tomorrow!!!',
    'tomorrow +1 day' => 'day after tomorrow? YEAH', 
);
foreach($compare_dates => $compare_date => $compare_date_desc){
    if(strtotime($compare_date) > $timestamp && $timestamp < strtotime($compare_date.' +1 day') ){
        echo $compare_date_desc;
        break;
    }
}

编辑:有了这个你不必担心时间戳是否已经没有小时,分钟和秒…或者创建不同的输出日期,将echo $compare_date_desc;替换为echo date($compare_date_desc,$timestamp);

<?php
$time = "20060713174545";
$date = date('Y-m-d', strtotime($time));
$now = date('Y-m-d');
$tomorrow = date('Y-m-d', time() + strtotime('tomorrow'));
$day_after_tomorrow = date('Y-m-d', time() + strtotime('tomorrow + 1 day'));
if ($date == $now){
    echo "It's today";
} 
elseif($date == $tomorrow){
    echo "It's tomorrow";
}
elseif($date == $day_after_tomorrow){
    echo "It's day after tomorrow";
}
else{
    echo "None of previous if statements passed";
}
<?php
function getTheDay($date)
{
   $curr_date=strtotime(date("Y-m-d H:i:s"));
   $the_date=strtotime($date);
   $diff=floor(($curr_date-$the_date)/(60*60*24));
switch($diff)
  {
     case 0:
     return "Today";
         break;
     case 1:
     return "Yesterday";
        break;
     default:
        return $diff." Days ago";
    }
  }
?>