如何检查时间跨度PHP功能不到1小时,今天和昨天?

I tryed to display added date as 25 minutes ago, Today 5.30 PM etc.

$added_time  = strtotime('1 Jan 2016 6:00 AM');
$currentTime = strtotime('1 Jan 2016 7:15 AM'); // probably uses time()
$diff = timespan($time1, $time2);

if($diff < 1 hour){ // how to check 1 hour 
 //display minutes ago
}
else {
 //display added time 
}

Conditions

  • if the time gap is less than 60 minute -> 25 minutes ago

  • If the time gap is over 60 minute But Today -> Today 6.00AM

  • If the time gap is over 60 minute But Yesterday -> Yesterday 6.00AM

  • Else exactly $added_time

How to check the condition for less than 1 hour, today and yesterday?

This is not specifically a CodeIgniter question. I am not sure exactly what you are doing, but this code will get you close.

$Added = new \DateTime(date('Y-m-d H:i:s', strtotime('1 Jan 2016 6:00 AM')));
$Current = new \DateTime(date('Y-m-d H:i:s', strtotime('1 Jan 2016 7:15 AM')));
$Diff = $Added->diff( $Current , FALSE);

$hours = $Diff->format('%H');
$mins = $Diff->format('%I');

if( $Diff->invert == true ){
    echo "Some hours $hours and minutes $mins ago ";
}
else if( $Diff->invert == false ){
    echo "Some hours $hours and minutes $mins into the future ";
}

References:

http://php.net/manual/en/class.datetime.php

http://php.net/manual/en/datetime.diff.php