[英]How to define start and end times in python
I am using the code 我正在使用代码
def run_periodically(start, end, interval, func):
event_time = start
while event_time < end:
s.enterabs(event_time, 0, func, ())
event_time += interval + random(-5, 45)
s.run()
run_periodically(time()+5, time()+1000000, 10, getData)
Now If I wanted to define the start time as 22.00 how is this formatted in python? 现在,如果我想将开始时间定义为22.00,如何用python格式化?
eg I would change the code to 例如我将代码更改为
starttime = #?#
run_periodically(starttime(), time()+1000000, 10, getData)
What is the standard time formatting used to make this work? 使这项工作使用的标准时间格式是什么?
The Python time() related functions take the number of seconds since a particular date (depending on your os). 与Python time()相关的函数占用自特定日期以来的秒数(取决于您的操作系统)。 You can convert that from the datetime
types using datetime.time()
您可以使用datetime.time()
从datetime
类型进行转换。
import datetime
timestamp = datetime.datetime(2013, 6, 4, 6, 18, 1).time()
That makes timestamp
usable for run_periodically
. 这使得timestamp
可用于run_periodically
。
You can also go the other way by using datetime.fromtimestamp(time.time())
. 您还可以使用datetime.fromtimestamp(time.time())
。 All this and more detailed info can be found in the module documentation . 所有这些以及更详细的信息都可以在模块文档中找到。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.