【发布时间】:2019-06-07 22:43:11
【问题描述】:
我一直在考虑做一个睡眠功能,它会一直睡到某个日期被调用。我的想法基于日期,例如:2019-01-20 12:00:00。
我还没有真正想出如何开始解决这个问题。我的想法是类似的,例如
if there is a date given:
time.sleep(until the date and time)
所以问题是我怎么可能能够睡到 2019-01-20 12:00:00 的特定时间?
【问题讨论】:
-
提示:
time.sleep()预计秒数。查看time.strptime()将字符串转换为自 1970-01-01 00:00 以来的秒数。 -
如果你想这样做,因为当时应该运行一些代码,看看Python标准库,它带有一个调度程序! docs.python.org/3/library/sched.html