python生成HTTP头中GMT时间格式的字符串

关于GMT时间,参见帖子:
http://www.malaoshi.top/show_1EF1TS4sSI6v.html

import datetime
GMT_FORMAT = '%a, %d %b %Y %H:%M:%S GMT'
# utcnow()方法生成utc时间
datetime.datetime.utcnow().strftime(GMT_FORMAT)

如果将字符串转成GMT时间,如下:

TIME = 'Sun, 08 Jul 2018 23:55:33 GMT'
datetime.datetime.strptime(TIME, GMT_FORMAT)

注意:此时的时间,与北京时间相差8小时,转换时区需要额外处理,用开源的pytz库

感谢文章:
https://blog.csdn.net/xuezhangjun0121/article/details/80394518


原文出处:/show_1EF1TS9xSxrw.html