gpt4 book ai didi

python - strtotime 等效?

转载 作者:太空狗 更新时间:2023-10-29 17:13:30 25 4
gpt4 key购买 nike

我正在使用它来将日期时间字符串转换为 unix 时间戳:

str(int(time.mktime(time.strptime(date,"%d %b %Y %H:%M:%S %Z"))))

但是日期结构经常不一样,所以我不断收到以下错误消息:

time data did not match format: data=Tue, 26 May 2009 19:58:20 -0500 fmt=%d %b %Y %H:%M:%S %Z

有谁知道有什么简单的函数可以将日期/时间的字符串表示形式转换为 python 中的 unix 时间戳?我真的不想每次都在循环中打开一个进程来调用 php 脚本来回显时间戳:)

最佳答案

from dateutil.parser import parse

parse('Tue, 26 May 2009 19:58:20 -0500').strftime('%s')

# returns '1243364300'

关于python - strtotime 等效?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3894010/

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