假设我有一个 start_date
start_date = datetime.time(7, 55, 56)
我创建了一个时间表:
timelist = []
for y in range(0, 24, 1):
for x in range(0, 60, 5):
start = datetime.time(y, x)
timelist.append(start)
timelist = [datetime.time(0, 0),
datetime.time(0, 10),
datetime.time(0, 20),
datetime.time(0, 30),
datetime.time(0, 40),
datetime.time(0, 50),
datetime.time(1, 0),
...]
x.hour
退货[0, 1, 2, ..., 23]
x.minute
退货[0, 10, 20, 30, 40, 50]
然后我想创建一个字典{ [time: 00:00:00, value: 0], [time: 00:10:00, value=0], ... }
现在时间是 x。并且该值是通过检查开始时间何时创建的:
例如:
start_date = 07:55:56 → at 07:50:00 value = 1
start_date = 08:03:22 → at 08:00:00 value = 1
start_date = 08:18:00 → at 08:10:00 value = 1
否则值为 0
我需要帮助创建用于检查分钟的 if 语句。
到目前为止,我有:
for x in timelist:
if x.hour == start_date.hour:
...