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

HOW CAN I FORMAT MINUTES:SECONDS
???

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);

Output

Fiddle

Hello, buddy!

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

您可能感兴趣的

Skip the variable from Php to js? I am trying to send MY location to my js file. The location have the gives correct value when it is echoed from php. But...
PHP后端之验证码 PHP后端之验证码 前言: 打算写一些实际开发中遇到的东西。我这个人记性不好,觉得记下来,以后就算想找,也能找得到。 PHP,可能很长一段时间都不会使用了。所以还是留一些记录。 另外还有一些服务器架设的总结,之后整理了...
Bitwise operators will not translate JavaScript to... I'm trying to translate this segment of code which makes use of bitwise operators in a loop, from JavaScript to PHP. Her...
Gentoo – New slot for PHP 7.2 on amd64 PHP 7.2 just went stable on amd64 providing me with an opportunity to finally migrate away from PHP 7.0. Unlike the PHP ...
Advanced Session Tomcat vs. Pivotal tc Server Could anyone advise as to the pros and cons of using Pivotal tc Serve...