请求 英文:[Python]Python网页编程 - 解析和生成 Last-Modified-Time

来源:百度文库 编辑:九乡新闻网 时间:2024/04/27 09:27:06
Python语言: Python网页编程 - 解析和生成 Last-Modified-Time#From: http://bugbox.blogspot.com/2005/05/python-with-last-modified-time.html
#
#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.