繁体   English   中英

Python日期时间无法解释的秒和微秒之间的差异

[英]Python datetime unexplained difference between seconds and microseconds

这里发生了什么?

>>> a = datetime.datetime.now()
# waiting....
>>> b = datetime.datetime.now()
>>> c = b - a
>>> c.seconds
4
>>> c.microseconds
884704

微秒如何比秒数大2倍? 我想要微秒的精度(然后自己将其转换为秒),但这似乎是错误的。

884704微秒是0.884704秒。

>>> c = datetime.timedelta(seconds=4, microseconds=884704)
>>> c.seconds
4
>>> c.microseconds
884704
>>> print(c)
0:00:04.884704

要获得总秒数,可以使用total_seconds()

>>> c.total_seconds()
4.884704

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM