Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (47.6k points)

datetime.datetime.utcnow()

Why does this datetime not have any timezone info given that it is explicitly a UTC datetime?

I would expect that this would contain tzinfo.

1 Answer

0 votes
by (106k points)

The meaning of datetime.datetime.utcnow() means it is timezone naive, so you can't use it with datetime.astimezone

you can give it a timezone like this

import pytz 

pytz u = datetime.utcnow() 

u = u.replace(tzinfo=pytz.utc)

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...