The Python standard library does not implement time zones. You should use python-dateutil . It provides useful extensions for the standard datetime module, including time zone implementations and an analyzer.
Using .astimezone(dateutil.tz.tzutc()) you can convert the time zones of datetime objects to UTC. For the current time as a timezone datetime object, you can use datetime.datetime.utcnow().replace(tzinfo=dateutil.tz.tzutc()) .
import dateutil.tz cet = dateutil.tz.gettz('CET') cesttime = datetime.datetime(2010, 4, 1, 12, 57, tzinfo=cet) cesttime.isoformat() '2010-04-01T12:57:00+02:00' cettime = datetime.datetime(2010, 1, 1, 12, 57, tzinfo=cet) cettime.isoformat() '2010-01-01T12:57:00+01:00'
Unfortunately, this method will not be correct during the switch to daylight saving time.
source share