我应该如何将90060(秒)最好地转换为字符串“25h 1m”?
目前我在SQL中进行以下操作:
SELECT
IF(
HOUR(
sec_to_time(
sum(time_to_sec(task_records.time_spent))
)
) > 0,
CONCAT(
HOUR(sec_to_time(sum(time_to_sec(task_records.time_spent)))),
'h ',
MINUTE(sec_to_time(sum(time_to_sec(task_records.time_spent)))),
'm'
),
CONCAT(
MINUTE(sec_to_time(sum(time_to_sec(task_records.time_spent)))),
'm'
)
) as time
FROM myTable;
但我不确定这是否是最方便的方法 :-)
我欢迎在SQL(与我已经做的方式不同)或PHP中进行此操作的建议。
编辑:
所需字符串的示例:“5m”,“40m”,“1h 35m”,“45h”“46h 12m”。
1天1小时1分钟
,而不是25小时1分钟
吗? - Basile Starynkevitch