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.
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)
pytz
(e.g. pytz.utc
instead of timezone.utc
)
May 27, 2020 at 3:09
datetime.py
under the same directory?sys.path
.timezone
is not a standard python module. Perhaps you meanpytz.timezone
(you'll have to install pytz) ordatetime.tzinfo
?from datetime import timezone
is valid in python3 but not python2. I'm not sure what the replacement is.