Created
September 1, 2013 10:45
-
-
Save Fedcomp/6403665 to your computer and use it in GitHub Desktop.
Миллисекунды в человеко-читаемый вид.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//echo 'Я знаю '.declOfNum(5, array('иностранный язык', 'иностранных языка', 'иностранных языков')); | |
function declOfNum($number, $titles) | |
{ | |
$cases = array (2, 0, 1, 1, 1, 2); | |
return $number." ".$titles[ ($number%100>4 && $number%100<20)? 2 : $cases[min($number%10, 5)] ]; | |
} | |
function seconds_to_words($seconds) { | |
if ($seconds < 0) return "Неизвестно"; | |
if ($seconds == 0) return "Ноль секунд"; | |
$hours = intval($seconds/pow(60,2)); | |
$minutes = intval($seconds/60)%60; | |
$seconds = $seconds%60; | |
$out = ""; | |
if ($hours > 0) $out .= declOfNum($hours, array('час', 'часа', 'часов')). ' '; | |
if ($minutes > 0) $out .= declOfNum($minutes, array('минута', 'минуты', 'минут')). ' '; | |
if ($seconds > 0) $out .= declOfNum($seconds, array('секунда', 'секунды', 'секунд')). ' '; | |
return trim($out); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment