python - python 中的 Rfc 1123

只想使用“日期时间”或“时间”模块。我将以下代码基于 this问题:

import time

def rfc1123 (gmt):
    weekday = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"][gmt.tm_wday]

    month = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"][gmt.tm_mon]

    return "%s, %02d %s %04d %02d:%02d:%02d GMT" % (weekday, gmt.tm_mday, month, gmt.tm_year, gmt.tm_hour, gmt.tm_min, gmt.tm_sec)

print (rfc1123 (time.gmtime ()))

有什么问题吗?我真的很担心 DST。

谢谢。

最佳答案

更简单的方法:

from time import strftime, gmtime
strftime("%a, %d %b %Y %H:%M:%S +0000", gmtime())

参见 python 中的示例 python documentation

https://stackoverflow.com/questions/3661574/

相关文章:

file - 如果文件长度相同,哈希冲突的可能性有多大?

open-source - 用于检测运行笔迹的开源

python - 为每个类别选择一个项目的查询语法

vi - 如何利用 "vi -t"查找系统调用的源码? FreeBSD

orm - Eclipselink - 坚持后的ID仍然为空

sql - 对于每个唯一的 A 列,什么 SQL 查询返回具有最新日期和时间(B 列和 C 列)的行

git - 如何使用 ssh 将 repo 克隆到远程服务器

asp.net-mvc - ASP.Net MVC 2.0 : unescaping URL que

ejabberd - 如何阻止 ejabberd 使用 mnesia

PHP - 如何将页面标题添加到 URL?以及如何使用 PHP 创建干净的 url