简体   繁体   English

python - 如何将时间显示为纪元?

[英]python - how to display time as epoch?

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?我需要将当前时间显示为 python 中的一个纪元,以作为变量传递给某些代码,我该怎么做?

ie. IE。 1458410416

Every method of每一种方法

import datetime
datetime.datetime()

gives human readable values.给出人类可读的值。

There is a built-in function in the time module: time模块中有一个内置函数:

import time

seconds = time.time()

There are many functions in the time module for seconds since the Epoch, time tuples, etc. I would recommend that you check out the docs .自 Epoch 以来, time模块中有许多函数,时间元组等。我建议您查看docs

Import the time library, and then use this code:导入time库,然后使用以下代码:

>>> time.mktime(datetime.datetime.now().timetuple())
1458410651.0

time.mktime converts a datetime to a Unix epoch timestamp. time.mktimedatetime时间转换为 Unix 纪元时间戳。

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

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