Converting from local -> UTC
Sebastian "lunar" Wiesner
basti.wiesner at gmx.net
Sat Jul 12 10:16:28 EDT 2008
Gabriel Genellina <gagsl-py2 at yahoo.com.ar>:
> En Fri, 11 Jul 2008 15:42:37 -0300, Keith Hughitt
> <keith.hughitt at gmail.com> 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 http://python.active-venture.com/lib/datetime-datetime.html), 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 <http://docs.python.org/lib/datetime-tzinfo.html> may be enough.
> A more complete implementation is at <http://pytz.sourceforge.net/>
The python-dateutil package also provide classes to deal with timezone-aware
datetime objects. See <http://labix.org/python-dateutil>
--
Freedom is always the freedom of dissenters.
(Rosa Luxemburg)
More information about the Python-list
mailing list