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() - 59*60); // 59 vинут назад echo "\n"; echo humanTimeAgo(time() - 15*60); // 15 минут назад echo "\n"; echo humanTimeAgo(time() - 59*60); // 59 vинут назад echo "\n"; echo humanTimeAgo(time() - 59); // 59 секунд назад
Output for 7.0.0 - 7.0.33, 7.1.0 - 7.1.25, 7.2.0 - 7.2.13, 7.3.0
27.04.2017 в 21:17 23 часов назад 1 часов назад 0 минут назад 1 часов назад 0 минут назад
Output for 5.6.38
Catchable fatal error: Argument 1 passed to humanTimeAgo() must be an instance of int, integer given, called in /in/mkSaW on line 30 and defined in /in/mkSaW on line 5
Process exited with code 255.

preferences:
88.01 ms | 401 KiB | 81 Q