【发布时间】:2016-04-05 05:35:54
【问题描述】:
我想编写一个小python,它需要每天在特定时间(例如下午 1 点)生成一个简单的精确时间戳(脚本将每天运行)。我写了这样的东西:
from datetime import datetime
now = datetime.utcnow() # Current time
then = datetime(1970,1,1) # 0 epoch time
ts = now - then
ts = ts.days * 24 * 3600 + ts.seconds
print ts
这很好,但我想通过now 来获取我每天的时间字段。我该怎么做?
【问题讨论】:
-
我有点不清楚你想做什么。
time_field是什么? -
now是日期和时间。ts = now - then是自then以来的持续时间...你到底想要什么? -
我的最终结果应该是一个时间戳,必须在每天下午 1 点(比如说)生成。由于上面的代码给出了当前时间,我想要一个特定时间的时间戳。
-
time.time()有什么问题?