gpt4 book ai didi

python - 如何将此日期字符串转换为 "2011-02-15T12:00+00:00"python 日期时间对象

转载 作者:行者123 更新时间:2023-11-28 20:53:21 24 4
gpt4 key购买 nike

如何将此日期字符串转换为以下格式的“2011-02-15T12:00+00:00”python 日期时间对象“Wed, Feb, 15, 2011 15:00”?

最佳答案

好像是ISO 8601格式。尝试使用 iso8601包 - 你可以通过 pipeasy_install 安装它。

Many file formats and standards use the ISO 8601 date format (e.g. 2007-01-14T20:34:22+00:00) to store dates in a neutral, unambiguous manner. This simple module parses the most common forms encountered and returns datetime objects.

>>> import iso8601
>>> iso8601.parse_date("2007-06-20T12:34:40+03:00")
datetime.datetime(2007, 6, 20, 12, 34, 40, tzinfo=<FixedOffset '+03:00'>)
>>> iso8601.parse_date("2007-06-20T12:34:40Z")
datetime.datetime(2007, 6, 20, 12, 34, 40, tzinfo=<iso8601.iso8601.Utc object at 0x100ebf0>)

关于python - 如何将此日期字符串转换为 "2011-02-15T12:00+00:00"python 日期时间对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5012592/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com