Feedparser and dates

Fredrik Lundh fredrik at pythonware.com
Wed Mar 15 14:36:39 CET 2006


"friis" wrote:

> I'm using FeedParser.org to import feeds into our MySQL database.
> Our problem is that we haven't found a solution to translate the date
> of a post item into GMT.

from what I can tell, feedparser returns a 9-item UTC time tuple (which
is the same thing as GMT, at least for all practical purposes).

if it's a standard timestamp you want, you can use calendar.timegm:

>>> t = (2004, 1, 1, 19, 48, 21, 3, 1, 0)
>>> import calendar
>>> calendar.timegm(t)
1072986501
>>> import time, datetime
>>> time.asctime(time.gmtime(calendar.timegm(t)))
'Thu Jan 01 19:48:21 2004'
>>> datetime.datetime.utcfromtimestamp(calendar.timegm(t))
datetime.datetime(2004, 1, 1, 19, 48, 21)

</F> 






More information about the Python-list mailing list