gpt4 book ai didi

python - 使用strptime转换特定时间格式

转载 作者:行者123 更新时间:2023-12-01 06:15:42 25 4
gpt4 key购买 nike

我正在尝试转换

[16/Jan/2010:18:11:06 +0100] (common log format)

到时间戳。如何使用 strptime 来转换它?

时区可以不同于+0100

最佳答案

import time
log = '16/Jan/2010:18:11:06 +0100'
dt = time.strptime(log, '%d/%b/%Y:%H:%M:%S +0100')

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

Python 的时区支持存在问题并且依赖于平台。
请参阅this post (另见第一部分)。

关于python - 使用strptime转换特定时间格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3452188/

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