【问题标题】:How do microseconds work in a datetime.timedelta?微秒如何在 datetime.timedelta 中工作?
【发布时间】:2019-09-13 21:58:53
【问题描述】:

在下面的示例中 - 我得到的秒值与微秒不匹配。这让我很困惑。有人能解释一下吗?

>>> a
datetime.datetime(2019, 9, 13, 21, 47, 46, 837435, tzinfo=<UTC>)
>>> b
datetime.datetime(2019, 9, 13, 21, 47, 54, 724570, tzinfo=<UTC>)
>>> (b-a).microseconds
887135
>>> (b-a).seconds
7
>>> (b-a)
datetime.timedelta(seconds=7, microseconds=887135)

【问题讨论】:

  • 对我来说看起来是正确的。究竟哪些数字不匹配?

标签: python python-datetime timedelta


【解决方案1】:

微秒不是以微秒为单位的增量,它是以微秒为单位的非整数提醒。 时差是7秒和887135微秒

【讨论】:

    【解决方案2】:

    我刚刚意识到 (b-a).seconds 不应该等同于 (b-a).microseconds。这里的确切时间差是 (b-a).seconds + (b-a).microseconds。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-10-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-26
      • 1970-01-01
      • 2022-10-19
      • 1970-01-01
      相关资源
      最近更新 更多