python - python 中的 Rfc 1123

标签 python time dst

只想使用“日期时间”或“时间”模块。我将以下代码基于 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

关于python - python 中的 Rfc 1123,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3661574/

相关文章:

java - 在 Java 和 C++ 之间同步日期

php - DateTime 对象不受其时间戳的约束?

python - 如何将 Django 应用程序部署到无法使用 pip 的服务器上

python - 在Kivy中访问Label的texture_size属性

Java静态方法变量在编译时解析,在运行时加载?

r - 将Zoo转换为数据框

php - 将来如何设置时间戳

c# - 为什么 .NET 不能正确转换时间?

python - 将多个元素附加到 numpy 数组

python - 使用 statsmodels 进行 ARMA 样本外预测