我试着做一个小脚本来使用文本文件中的时间,然后在这个数字上加上30分钟,然后与“currenttime”进行比较,看看是否已经过了30多分钟。。。你知道吗
import os
from time import time, sleep, strftime
with open('timecheck.txt') as timecheck:
last_timecheck = timecheck.read().strip()
print last_timecheck
currenttime = strftime('%H:%M:%S')
if last_timecheck + 30 >= currenttime:
if os.path.exists("../test.csv"):
with open("timecheck.txt", 'wb') as timecheck:
timecheck.write("1")
else:
currenttime = strftime('%H:%M:%S')
with open("timecheck.txt", 'wb') as timecheck:
timecheck.write(currenttime)
任何帮助都将不胜感激,我不知道如何正确地做这件事。你知道吗
不是为当前时间创建字符串,而是使用^{} 解析从文件读取的字符串,例如:
检查是否超过30分钟。你知道吗
您可能应该在写入文件的信息中包含日期。如果不这样做,那么
23:30:45
就永远不会是当天的“30分钟前”。你知道吗如果不需要时间戳使其可读,只需写入UNIX时代以来的秒数:
这是一个浮点值,您可以使用以下命令再次读取它:
由于它是一个数字表示,因此您可以测试30分钟是否已过,并使用:
相关问题 更多 >
编程相关推荐