Python3查找两个纪元毫秒时间之间的持续时间

发布于 2025-01-16 03:57:07 字数 358 浏览 0 评论 0原文

我有两个纪元时间(以毫秒为单位),我需要找到它们之间的持续时间。 例如:

1637264400000 - 2021 年 11 月 18 日 11:40:00 AM

1637280000000 - 2021 年 11 月 18 日 4:00:00 PM

在这种情况下,时差为 4 小时 20 分钟。我尝试减去两次,如下所示:

1637280000000 - 1637264400000 = 15600000

但后来我不知道如何计算持续时间 15600000 。如果我使用纪元时间转换器,则 15600000 只是转换为 June 30, 1970 6:20:00 AM 。

那么,如何计算天/小时/分钟的持续时间?

I have two epoch times in milliseconds, I need to find the duration between them.
For instance:

1637264400000 - November 18, 2021 11:40:00 AM

1637280000000 - November 18, 2021 4:00:00 PM

In this case the time difference is 4 hours and 20 minutes. I tried to subtract the two times as in :

1637280000000 - 1637264400000 = 15600000

But then I don't know how to compute 15600000 in duration. If I used an epoch time convertor then 15600000 just converts to June 30, 1970 6:20:00 AM .

So, how do I compute the duration in days/hours/minutes?

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

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

发布评论

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

评论(1

绅士风度i 2025-01-23 03:57:07

出于所有实际目的,您可能希望使用 timedelta< /code>实例。仅使用毫秒增量:

>>> from datetime import timedelta
>>> print(timedelta(milliseconds=15600000))
4:20:00

For all practical purposes you probably want to work with a timedelta instance. Using only the milliseconds delta:

>>> from datetime import timedelta
>>> print(timedelta(milliseconds=15600000))
4:20:00
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文