示例:
seonds =“1015557”;
结果应该是:
11days 18h:05m:57s
如何在MySQL中执行此操作?
答案 0 :(得分:6)
s/regular expression/replacement/flags
产生
select concat(
format(floor(s / @day),0),
'days ',
time_format(sec_to_time(s % @day),'%Hh:%im:%ss')
) formatted_date
from (select 1015557 s) t, (select @day = 3600 * 24);
答案 1 :(得分:6)
您可以使用以下查询:
SELECT
DATE_FORMAT(date('1970-12-31 23:59:59')
+ interval 1015557 second,'%j days %Hh:%im:%ss') as result;
<强>样品强>
mysql> SELECT
-> DATE_FORMAT(date('1970-12-31 23:59:59')
-> + interval 1015557 second,'%j days %Hh:%im:%ss') as result;
+----------------------+
| result |
+----------------------+
| 011 days 18h:05m:57s |
+----------------------+
1 row in set (0,00 sec)
mysql>
答案 2 :(得分:2)
你可以尝试一下:
SET @seconds = 1015557;
SELECT CONCAT(
FLOOR(TIME_FORMAT(SEC_TO_TIME(@seconds), '%H') / 24), 'days ',
MOD(TIME_FORMAT(SEC_TO_TIME(@seconds), '%H'), 24), 'h:',
TIME_FORMAT(SEC_TO_TIME(@seconds), '%im:%ss')
)
AS Result
结果应该是:
11days 18h:05m:57s
希望这会有所帮助!
答案 3 :(得分:2)
SELECT *
, CONCAT( FLOOR(sec/3600),"hour ", FLOOR(MOD(sec,3600)/60),"min ",MOD(sec,60),"sec")
FROM table_1