Php convert seconds to minutes: seconds only

综合编程 2018-05-28 阅读原文

This question already has an answer here:

  • Convert one date format into another in PHP 12 answers

I am using this function to convert seconds to minutes:

function convert($iSeconds)
    return date('i:s', mktime(0, 0, $iSeconds));

It works great. But if I use this code:

echo convert(3605);

It returns 00:05
. But I need to return like this: 60:05


You can't use mktime()
or strtotime()
for this kind of conevrsions. You can calculate this manually. You can try this -

function convert($iSeconds)
   $min = intval($iSeconds / 60);
   return $min . ':' . str_pad(($iSeconds % 60), 2, '0', STR_PAD_LEFT);

echo convert(7205);



Hello, buddy!

责编内容by:Hello, buddy!阅读原文】。感谢您的支持!


Is it an Active Record class where (&... I got a question on Active Record Class usage, my code snippet below. $this...
What is gc_enable for PHP exactly&q... Before you tell me to read the manual, check out the documentation f...
PHP Versions Stats – 2017.2 Edition – ... It's stats o'clock! See2014, 2015 , 2016.1 ,2016.2 and2017.1 for previous simil...
15 Top PHP Coding Tutorials, Tips and Tricks PHP is a widely-used scripting language that is suited for web development and ...
深入理解PHP之echo echo 作为PHP中的语言结构, 经常会被使用, 因此了解他的实现还是有必要的. 版本 源码地址 ...