简体   繁体   中英

How to convert an unaware datetime to UTC time in Python?

I am trying to convert an unaware datetime to UTC time in Python.

I have:

  • datetime
  • location (latitude and longitude)

I am finding the timezone of my datetime based on the location with

tz.timezone_at(lat=latitude, lng=longitude)

I am now trying to attach this timezone to my datetime to be able to convert it after to UTC. However I am failing at this step.

I have tried:

interview_slot = interview_slot.replace(tzinfo=ZoneInfo(store_timezone))

But unable to import the library that allows me to use ZoneInfo. Do you have another way to do it?

Thank you

Try the answers from this question

Moreover, pytz should be firstly installed from cmd like this: pip install pytz

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM