Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 不能在过去的条件中设置时间_Python 3.x - Fatal编程技术网

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