I'm trying to convert a timezone aware datetime to UTC, but without carrying an offset:
I receive some data to create a start date for an event: year, month, day, hours, minutes
I have a venue
object and use its longitude and latitude to obtain the venue timezone like so:
from datetime import datetime
import pytz
from timezonefinder import TimezoneFinder
tf = TimezoneFinder()
tz_str = tf.timezone_at(lng=venue.longitude, lat=venue.latitude)
For instance tz_str
can take the value 'Asia/Tokyo'
I then create a timezone aware datetime object:
start_date = datetime(2020, 3, 1, 9, 0, 0, 0, pytz.timezone(tz_str))
this will have the value datetime.datetime(2020, 3, 1, 9, 0, tzinfo=<DstTzInfo 'Asia/Tokyo' LMT+9:19:00 STD>)
I would like to convert it to UTC before storing to the DB, but I don't want the offset.
If I simply convert to UTC, it will keep the offset which I don't want:
utc_start_date = start_date.astimezone(pytz.utc)
this will take the following value datetime.datetime(2020, 2, 29, 23, 41, tzinfo=<UTC>)
, which is 19 minutes off.
How can I remove the offset?