python - 如何将时间显示为纪元? [英] python - how to display time as epoch?
本文介绍了python - 如何将时间显示为纪元?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在 python 中将当前时间显示为一个纪元,以作为变量传递给一些代码,我该怎么做?
即.1458410416
导入日期时间日期时间.日期时间()
提供人类可读的值.
解决方案
导入time
库,然后使用这段代码:
time.mktime
将 datetime
转换为 Unix 纪元时间戳.
I need to display the current time as an epoch in python to pass as a variable into some code how do I go about doing that?
ie. 1458410416
Every method of
import datetime
datetime.datetime()
gives human readable values.
解决方案
Import the time
library, and then use this code:
>>> time.mktime(datetime.datetime.now().timetuple())
1458410651.0
time.mktime
converts a datetime
to a Unix epoch timestamp.
这篇关于python - 如何将时间显示为纪元?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文