3v4l.org

run code in 300+ PHP versions simultaneously
<?php date_default_timezone_set('Europe/Moscow'); function humanTimeAgo(int $time) { if ($time < 0) { return false; } $difference = time() - $time; if ($difference < 0) { return false; } $hours = round($difference / 3600); if ($hours < 1) { return date('i минут назад', $difference); } if ($hours < 24) { return $hours . ' часов назад'; } return date('d.m.Y в H:i', $time); } echo humanTimeAgo(time() - 24*3600 - 10*60); // 1 день и 10 минут назад echo "\n"; echo humanTimeAgo(time() - 23*3600 - 20*60); // 23 часа 20 минут назад echo "\n"; echo humanTimeAgo(time() - 10*60); // 10 минут назад
Output for 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.26, 7.3.0 - 7.3.13, 7.4.0 - 7.4.1
27.04.2017 в 20:13 23 часов назад 10 минут назад
Output for 5.6.0 - 5.6.40
Catchable fatal error: Argument 1 passed to humanTimeAgo() must be an instance of int, integer given, called in /in/ijk8j on line 30 and defined in /in/ijk8j on line 5
Process exited with code 255.

preferences:
133.63 ms | 401 KiB | 157 Q