2005年5月20日

Python with Last-Modified-Time

Doing web programing sometime need to parse/create the Last-Modified-Time, Last-Modified-Since, or Date... values in the RFC2822 format. And I always forget the format string. Here we go:




>>> import time
>>> time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime())
'Fri, 20 May 2005 11:08:40 GMT'
>>> t = time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime(time.time()))
>>> t
'Fri, 20 May 2005 11:22:20 GMT'
>>> time.strptime(t, "%a, %d %b %Y %H:%M:%S GMT")
(2005, 5, 20, 11, 22, 20, 4, 140, -1)


So what these tell us? Well, the format string is:
"%a, %d %b %Y %H:%M:%S GMT"


That's it. Yes, it is GMT time, no timezone there.

没有评论: