Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python cannot import timezone but can import datetime

if I write

from datetime import timezone

I get the error ImportError: cannot import name timezone

Of course calling datetime.timezone does not work either.

How do I debug this? I have wasted an hour and it is already late here.

like image 737
tst Avatar asked May 31 '18 00:05

tst


1 Answers

datetime.timezone was added in Python 3.2. So it is normal to get an import error in e.g. Python 2.7.

In Python 2.7, you can use the pytz library.

import datetime
import pytz

myDate = datetime.datetime.now(pytz.utc)
like image 173
Roland Smith Avatar answered Sep 20 '22 05:09

Roland Smith