import datetime
import calendar
import time
# utctime -> localtime
utcnow = datetime.datetime.utcnow()
local = datetime.datetime.fromtimestamp(calendar.timegm(utcnow.timetuple()))
# localtime -> utctime
localnow = datetime.datetime.now()
utc = datetime.datetime.urcfromtimestamp(time.mktime(localnow.timetuple()))
I have only tried it for a while and cannot guarantee it. If you handle the timezone properly, I think it is better to include python-dateutil.
Recommended Posts