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

您可能感兴趣的

Flexible Heredoc and Nowdoc Coming to PHP 7.3 Updates to the Heredoc and Nowdoc syntaxes proposed in a php.net RFC have been made for the upcoming PHP 7.3 release. The updates focus on improving l...
The PHP form does not redirect to correct pages I'm making a login page for the admins to make some changes to a website easily. However, the login page isn't working correctly. It won't go to the ...
PHP 内存泄漏分析定位 前言 本文开始撰写时我负责的项目需要用php开发一个通过 Socket 与服务端建立长连接后持续实时上报数据的常驻进程程序,在程序业务功能开发联调完毕后实际运行发送大量数据后发现内存增长非常迅速,在很短的时间内达到了 php 默认可用内存上限 128M ,并报错: Fatal...
How can I detect the current link of the page by p... actually i created a website in joomla, & in Facebook Page i give the link of that website page in iframe. I made an individual menu in joomla i...
PHP Script MySQL Select I am working on an app that needs to select data from a MySQL database. I am currently testing the PHP script via my browser to make sure that it is r...