相关疑难解决方法(0)

将秒转换为人类可读的持续时间

我怎样才能最好地将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;
Run Code Online (Sandbox Code Playgroud)

但我不确定这是最方便的方法:-)

我对在SQL(不同于我已经在做)或PHP中这样做的建议持开放态度.

编辑:

所需字符串的示例:"5m","40m","1h 35m","45h""46h 12m".

mysql time duration

21
推荐指数
2
解决办法
5万
查看次数

标签 统计

duration ×1

mysql ×1

time ×1