我需要实现根据已知时间日期获得当前日期与目标日期之差进而判断是否执行某个程序,还算简单,代码如下:
import time
def compare_time(time1,time2): #得到时间之差,为浮点型数据
s_time = time.mktime(time.strptime(time1,'%Y-%m-%d'))
e_time = time.mktime(time.strptime(time2,'%Y-%m-%d'))
return int(s_time) - int(e_time)
now = time.strftime('%Y-%m-%d',time.localtime(time.time()))
# now '2022-07-01'
result = compare_time(now,'2022-07-01')
if result!=0:
app = QApplication(sys.argv)
mainw = My_MainWindow()
mainw.show()
sys.exit(app.exec_())
else:
app = QApplication(sys.argv)
Ui = QMainWindow()
information = Ui_information()
information.setupUi(Ui)
Ui.show()
sys.exit(app.exec_())