Python 3.x 不能在过去的条件中设置时间
我需要做什么。Python 3.x 不能在过去的条件中设置时间,python-3.x,Python 3.x,我需要做什么。 我需要这个程序不允许用户输入过去的日期。当我按当前的方式尝试时,我收到以下错误消息。TypeError:“您实际上需要两个datetime对象来使用 from datetime import datetime from datetime import date def addNewItems(): end = 4 while end == 4: ToDoList = [ ] Name = input(
我需要这个程序不允许用户输入过去的日期。当我按当前的方式尝试时,我收到以下错误消息。TypeError:“您实际上需要两个
datetime
对象来使用
from datetime import datetime
from datetime import date
def addNewItems():
end = 4
while end == 4:
ToDoList = [ ]
Name = input("Enter the name of your task")
dateIn = input("Enter the task completion date. yyyy/mm/dd HH:MM:SS")
date = datetime.strptime(dateIn, "%Y/%m/%d %H:%M:%S")
now = datetime.now()
now_ = now.strftime("%d/%m/%Y %H:%M:%S")
if date < now_:
print("Time entered is in the past! Select options again")
continue
if Name in ToDoList:
print("Task already exists! Select options again")
continue
if date < now_ and Name not in ToDoList:
ToDoList.append(Name, date)
print("Task Added Sucessfully")
break