Apparently, I must run pytz.UTC.localize(datetime.datetime.now()) before I compare the current time with other “naive” time objects.
Why is that? Isn’t the current time relevant to specific time zones?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The
nowfunction does indeed return a naive object. It contains field values for day and time that are populated according to locale settings. That is why a separateutcnowis provided; that always gives you UTC field values (though it is still naive).