综合编程

Php convert seconds to minutes: seconds only

微信扫一扫,分享到朋友圈

Php convert seconds to minutes: seconds only
0

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!

Achieving high throughput with SQS using Akka Streams

上一篇

夜空中最亮的星,干涉了恐龙时代的环境

下一篇

您也可能喜欢

评论已经被关闭。

插入图片
Php convert seconds to minutes: seconds only

长按储存图像,分享给朋友