![](/img/trans.png)
[英]Python 2.7 - how can I find the difference between two datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S.%f') timestamps in seconds/microseconds?
[英]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.