从twitter日期到Python日期时间日期 [英] Going from twitter date to Python datetime date
本文介绍了从twitter日期到Python日期时间日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在收到以下格式从twitter发送的特定日期的短信:
I am receiving twitter messages that are sent at a certain date in the following format from twitter:
Tue Mar 29 08:11:25 +0000 2011
我想将这些日期存储在带时区的时间戳字段中在postgresql中使用djangos DateTimeField字段。当我存储该字符串但是我得到这个错误:
I want to store these dates in 'timestamp with time zone' field in postgresql with djangos DateTimeField field. When I store that string however I get this error:
ValidationError: [u'Enter a valid date/time in YYYY-MM-DD HH:MM[:ss[.uuuuuu]] format.']
我可以自动转换twitter数据类型到python datetime时间(在我的应用程序的其他地方可以保存日期)。
can I automatically transform the twitter datetype to a python datetime time (that does work elsewhere in my app for saving dates).
推荐答案
写这样的东西应将twitter日期转换为时间戳。
Writing something like this should convert a twitter date to a timestamp.
import time
ts = time.strftime('%Y-%m-%d %H:%M:%S', time.strptime(tweet['created_at'],'%a %b %d %H:%M:%S +0000 %Y'))
这篇关于从twitter日期到Python日期时间日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文