Tag "readable" (2)
Convert the timestamp to human-readable format like XX minutes ago or XX days ago. Was found here: http://stackoverflow.com/questions/2915864/php-how-to-find-the-time-elapsed-since-a-date-time ... Reveal Code
function humanTiming ($time)
{
$time = strtotime($time);
$time = time() - $time; // to get the time since that moment
$tokens = array (
31536000 => 'year',
2592000 => 'month',
604800 => 'week',
86400 => 'day',
3600 => 'hour',
60 => 'minute',
1 => 'second'
);
foreach ($tokens as $unit => $text) {
if ($time < $unit) continue;
$numberOfUnits = floor($time / $unit);
return $numberOfUnits.' '.$text.(($numberOfUnits>1)?'s':'').' ago';
}
}
$time = '2013-05-25 15:45:22';
echo 'Event happened '.humanTiming($time);
Convert the date/time interval in human-readable format ... Reveal Code
$startDate = 'now';
$endDate = '2013-08-12 14:30:00';
function date_diff($date1, $date2) {
$diff = strtotime($date2) - strtotime($date1);
return abs($diff);
}
function seconds2human($ss) {
$s = $ss % 60;
$m = floor(($ss % 3600) / 60);
$h = floor(($ss) / 3600);
return "$h hours, $m minutes, $s seconds";
}
echo "This file will expire in ". seconds2human(date_diff($startDate,$endDate));