0
1787
Convert any datetime object to UTC time
import time
import datetime
def to_utc(date_time):
timeStamp = time.mktime(date_time.timetuple()) + date_time.microsecond
return datetime.datetime.utcfromtimestamp(timeStamp)
datetime_field = datetime.datetime(2018, 12, 23, 14, 9, 21)
print("With local time\t", datetime_field)
print("With UTC time\t", to_utc(datetime_field))
With local time 2018-12-23 14:09:21
With UTC time 2018-12-23 08:39:21
Comment here