在 Python 中,如何将 datetime.datetime
转换为从 time.time
函数获得的那种 float
?
In Python, how do I convert a datetime.datetime
into the kind of float
that I would get from the time.time
function?
使用时间元组方法不难,仍然保留微秒:
It's not hard to use the time tuple method and still retain the microseconds:
>>> t = datetime.datetime.now()
>>> t
datetime.datetime(2011, 11, 5, 11, 26, 15, 37496)
>>> time.mktime(t.timetuple()) + t.microsecond / 1E6
1320517575.037496
这篇关于Python:从 `datetime.datetime` 转换为 `time.time`的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!