[Tutor] Processing unix style timestamp

Ravi Kondamuru ravikondamuru at gmail.com
Fri Mar 7 22:18:49 CET 2008


Thank you all for your insights.
mx.DateTime and feedparser seem to be the easiest to work with.
Ravi.

On Fri, Mar 7, 2008 at 4:36 AM, Kent Johnson <kent37 at tds.net> wrote:

> Ravi Kondamuru wrote:
> > I looked at datetime, but it seems slightly complex to work with non GMT
> > timestamps.
>
> Mark Pilgrim's Universal Feed Parser includes a robust date parser that
> works with your sample:
> In [1]: import feedparser as fp
> In [2]: fp._parse_date('Mon Feb 11 01:34:52 CST 2008')
> Out[2]: (2008, 2, 11, 7, 34, 52, 0, 42, 0)
>
> http://www.feedparser.org/
>
> This appears to be an RFC 2822-format date:
> http://www.faqs.org/rfcs/rfc2822.html
>
> feedparser uses these functions to parse the date string:
> In [4]: import rfc822
> In [5]: rfc822.parsedate_tz('Mon Feb 11 01:34:52 CST 2008')
> Out[5]: (2008, 2, 11, 1, 34, 52, 0, 1, 0, -21600)
> In [7]: rfc822.mktime_tz(_5)
> Out[7]: 1202715292.0
> In [8]: import time
> In [9]: time.gmtime(_7)
> Out[9]: (2008, 2, 11, 7, 34, 52, 0, 42, 0)
>
> The rfc822 module is deprecated; the same functions are now found in
> email.util.
>
> Kent
>



-- 
రవిచంద్ర కొండమూరు
(Ravi Kondamuru)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20080307/81933a4e/attachment-0001.htm 


More information about the Tutor mailing list