Converting from local -> UTC

Sebastian "lunar" Wiesner basti.wiesner at
Sat Jul 12 16:16:28 CEST 2008

Gabriel Genellina <gagsl-py2 at>:

> En Fri, 11 Jul 2008 15:42:37 -0300, Keith Hughitt
> <keith.hughitt at> escribi�:
>> I am having a little trouble figuring out how to convert a python
>> datetime to UTC. I have a UTC date (e.g. 2008-07-11 00:00:00). I would
>> like to create a UTC date so that when I send it to MySQL (which
>> treats all dates at local dates by default), it will already have
>> incorporated the proper UTC offset. I've tried looking through the
>> docs, but
>> have not had any luck.
> You have to use a "timezone aware" datetime object. If all you want is to
> store an UTC date, the tzinfo demo classes that you can find in the Python
> docs at <> may be enough.
> A more complete implementation is at <>

The python-dateutil package also provide classes to deal with timezone-aware
datetime objects.  See <>

Freedom is always the freedom of dissenters.
                                      (Rosa Luxemburg)

More information about the Python-list mailing list