Parsing dates

Matthew Schinckel matt at null.net
Thu Jun 15 19:08:33 EDT 2000


"Morten W. Petersen" <morten at src.no> wrote:
> Where is the package that'll accept the most different "DateTime"
> formats? I'm thinking along the lines of all the different ways
> mail-clients format their "Date:" header. --
> 
> -Morten
> 
> ------------------------------------------------------------- How to
> reply to email: http://home.sol.no/~vidaandr/news/OBSquoting.html
> (norsk) http://home.sol.no/~vidaandr/news/FAQquoting.html (english)
> 
> Who is the bigger fool? The fool or the fool who follows him?

The fool who cares :-)

Best method for handling dates in Date: headers is to use the rfc822
module:



(Sorry for the screwed up formatting - my newsreader/editor thinks I
want to work in XML!)



import rfc822, time

mail_file = open(filename,'r')

message = rfc822.Message(mail_file)

if message.has_key('date'):

date = message.get_date('date')

print time.mktime(date)



If it didn't work, the last two lines are indented one level.

Matt.



More information about the Python-list mailing list