Pas*_*ten 2 python datetime timedelta
这里发生了什么?
>>> a = datetime.datetime.now()
# waiting....
>>> b = datetime.datetime.now()
>>> c = b - a
>>> c.seconds
4
>>> c.microseconds
884704
Run Code Online (Sandbox Code Playgroud)
微秒怎么能比秒数多2倍?我想要微秒的精度(然后自己将其转换为秒),但这似乎是错误的.
884704
微秒意味着0.884704
秒.
>>> c = datetime.timedelta(seconds=4, microseconds=884704)
>>> c.seconds
4
>>> c.microseconds
884704
>>> print(c)
0:00:04.884704
Run Code Online (Sandbox Code Playgroud)
要获得总秒数,您可以使用total_seconds()
:
>>> c.total_seconds()
4.884704
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
269 次 |
最近记录: |