【发布时间】:2020-09-07 16:45:00
【问题描述】:
从Convert seconds into days, hours, minutes and seconds我们可以得到User Galvic的好功能:
function secondsToTime($seconds){
$dtF = new \DateTime('@0');
$dtT = new \DateTime("@$seconds");
return $dtF -> diff($dtT) -> format('%a days, %h hours, %i minutes and %s seconds');
}
echo secondsToTime(3600 * 24 * 31);
这很好用!但我想添加月份,然后我把 %m 个月 返回 0,%M 个月 返回两位数。
如何转换[1个月2天]的3600 * 24 * 32和[1年1个月]的3600 * 24 * 30 * 13?
因为Function of Galvic 中存在许多选项,但只有一个使用 2 行:GALVIC 函数,然后我想在这两行中添加选项“月、年”。
谢谢
【问题讨论】:
标签: php