gpt4 book ai didi

python-2.7 - 在python中将Twitter的日期格式转换为Datetime

转载 作者:行者123 更新时间:2023-12-03 23:47:50 30 4
gpt4 key购买 nike

Twitter 返回的日期时间格式是这种形式:

Thu Apr 23 13:38:19 +0000 2009

我要在 datetime数据库条目和查询的格式...

最佳答案

编辑 - 15 年 4 月 13 日
按照建议,请使用。

 datetime.strptime('Thu Apr 23 13:38:19 +0000 2009','%a %b %d %H:%M:%S +0000 %Y').replace(tzinfo=pytz.UTC)

现在,如果您想在日期解析和使用日期时间字符串方面进行大量工作,请使用 Babelpython-dateutil

请忽略下面的建议

我最近没有在 Python 上做太多工作,但这应该可以解决问题。
>>>from datetime import datetime
>>>d = datetime.strptime('Thu Apr 23 13:38:19 +0000 2009','%a %b %d %H:%M:%S %z %Y');
>>>print d.strftime('%Y-%m-%d');

这是基于 Python DocSO

关于python-2.7 - 在python中将Twitter的日期格式转换为Datetime,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18711398/

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