【问题标题】:Is it possible to construct a Python date using only standard libs with a http string timestamp [duplicate]是否可以仅使用带有 http 字符串时间戳的标准库来构造 Python 日期 [重复]
【发布时间】:2013-08-01 02:12:13
【问题描述】:

我有这样的字符串时间戳:

“格林威治标准时间 2013 年 7 月 31 日星期三 13:03:38”

我在 python 文档中看不到任何内容,但我可能错过了。

如果不是,我想我可以对字符串进行一些解析——因为它有一个固定的格式。任何有关如何开始的指示都会有所帮助。

日期符合 RFC 822。

【问题讨论】:

    标签: python


    【解决方案1】:

    是的!你需要使用strptime()

    import time
    time.strptime("30 Nov 00", "%d %b %y")
    

    这里是文档的链接:

    http://docs.python.org/2/library/time.html#time.strptime

    【讨论】:

    • 我最后这样做了:testdate = datetime.datetime.strptime(s, '%a, %d %b %Y %H:%M:%S GMT') 其中 s 是字符串.
    猜你喜欢
    • 2021-02-02
    • 1970-01-01
    • 2021-01-06
    • 2012-04-21
    • 2022-01-03
    • 2021-07-11
    • 2016-09-16
    • 2011-07-01
    • 2021-01-08
    相关资源
    最近更新 更多