Can't compare naive and aware datetime.now() <= challenge.datetime_end

后端 未结 9 1298
离开以前
离开以前 2020-12-02 07:58

I am trying to compare the current date and time with dates and times specified in models using comparison operators:

if challenge.datetime_start <= datet         


        
9条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-02 08:57

    Disable time zone. Use challenge.datetime_start.replace(tzinfo=None);

    You can also use replace(tzinfo=None) for other datetime.

    if challenge.datetime_start.replace(tzinfo=None) <= datetime.now().replace(tzinfo=None) <= challenge.datetime_end.replace(tzinfo=None):
    

提交回复
热议问题