如何在 SQLite 中将秒转换为 HH:MM:SS 格式?

发布于 2024-08-29 22:30:21 字数 37 浏览 3 评论 0原文

如何在 SQLite 中将秒转换为 HH:MM:SS 格式?

How would you convert secs to HH:MM:SS format in SQLite?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

a√萤火虫的光℡ 2024-09-05 22:30:21

试试这个:

sqlite> SELECT time(10, 'unixepoch');
00:00:10

Try this one:

sqlite> SELECT time(10, 'unixepoch');
00:00:10
清风不识月 2024-09-05 22:30:21

如果你的秒数超过24小时,则需要自己计算。例如,对于 100123 秒,向下舍入为分钟:

SELECT (100123/3600) || ' hours, ' || (100123%3600/60) ||' minutes.'
27 hours, 48 minutes

timestrftime 函数显然会将每 24 小时转换为另一天。因此,下面显示 3 小时(第二天的时间):

SELECT time(100123, 'unixepoch')
03:48:43

要获得完整的 27 小时,您可以单独计算小时,然后使用 strftime 计算分钟和秒:

SELECT (100123/3600) || ':' || strftime('%M:%S', 100123/86400.0);
27:48:43

If your seconds are more than 24 hours, you need to calculate it yourself. For example, with 100123 seconds, rounding down to minutes:

SELECT (100123/3600) || ' hours, ' || (100123%3600/60) ||' minutes.'
27 hours, 48 minutes

The time or strftime functions will obviously convert every 24-hours to another day. So the following shows 3 hours (the time on the next day):

SELECT time(100123, 'unixepoch')
03:48:43

To get the full 27 hours, you can calculate the hours separately, and then use strftime for the minutes and seconds:

SELECT (100123/3600) || ':' || strftime('%M:%S', 100123/86400.0);
27:48:43
被你宠の有点坏 2024-09-05 22:30:21

好吧,我会做这样的事情,但我得到了加 12 个小时......

SELECT strftime('%H-%M-%S', CAST(<seconds here> / 86400.0 AS DATETIME)) 

-- For subtracting the 12 hours difference :S
SELECT strftime('%H-%M-%S', CAST(<seconds here> / 86400.0 AS DATETIME) - 0.5) 

Well, i would do something like this, but i'm getting hours plus 12...

SELECT strftime('%H-%M-%S', CAST(<seconds here> / 86400.0 AS DATETIME)) 

-- For subtracting the 12 hours difference :S
SELECT strftime('%H-%M-%S', CAST(<seconds here> / 86400.0 AS DATETIME) - 0.5) 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文