python convert local time to utc code example
Example 1: python datetime to utc
from datetime import timezone
timestamp = dt.replace(tzinfo=timezone.utc).timestamp()
Example 2: utc to local time python
from datetime import datetime
from dateutil import tz
from_zone = tz.gettz('UTC')
to_zone = tz.gettz('America/New_York')
from_zone = tz.tzutc()
to_zone = tz.tzlocal()
utc = datetime.strptime('2011-01-21 02:37:21', '%Y-%m-%d %H:%M:%S')
utc = utc.replace(tzinfo=from_zone)
central = utc.astimezone(to_zone)