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!阅读原文】。感谢您的支持!


Switching from jQuery to PHP Here's the situation: I'm using jquery.validate.js to validate my forms, but I need to add a server-side validation la...
PHP 7.0.31 for Jessie On July 19th 2018, the PHP group published PHP 7.0.31 . This is a security release. Several security bugs have b...
也是拿來掃 PHP 程式碼的 PHPStan… PHPStan 也是 PHP 的靜態分析工具,官方給的 slogan 是「PHP Static Analysis Tool - discover bugs in your code without running it!」。然後官方給了一...
PHP Hybrid / Hacklang: use the t... I can't build hhvm at the moment for lack of access to a 64-bit VM, so I haven't been able to use the typechecker that t...
Linux PHP多版本切换 超简单办法 今天在帮别人安装一个不知所谓的东西时碰到,三版本的PHP环境,我感觉那个人也是666哒,他使用的是AMH快速开发工具 有图有真相!!! 然后就顺便写下怎么快速,简便切换php版本 首先:find命令找下php在哪里先 ...