0 votes
1 view
in Python by (47.8k 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 (107k 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
+1 vote
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...