eyecatch php

PHP

【PHP】秒数を元に経過時間を作成する方法

2015/01/11

経過時間を作成

秒数を元に「150時間42分」など、経過時間を作成する方法。
タイムカードの勤続時間などで使いました。

[php]
// $sec 秒数
$result = sprintf('%02d時間%s', $sec / 3600, gmdate('i分', $sec % 3600));

// 結果に秒数まで必要な場合
$result = sprintf('%02d時間%s', $sec / 3600, gmdate('i分s秒', $sec % 3600));
[/php]

-PHP
-,