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...
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.
1 Answer
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)