Going from twitter date to Python datetime date

前端 未结 10 1288
谎友^
谎友^ 2020-12-23 09:21

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

I want

10条回答
  •  既然无缘
    2020-12-23 10:15

    The initial problem I was having was converting from the datetime that the twitter api gives to String.

    The following works which addresses different comments people seem to have for above solutions which are a little unclear as to whether the starting date is already in string format or not. This works for Python 2.7

    With a tweet from the API, tweet.created_at gives the date in datetime format. At the top of your file, add from datetime import datetime

    then use the following to get the corresponding string.

    datetime.strftime(tweet.created_at,'%a %b %d %H:%M:%S %z %Y').
    

    You can then use this string as described in other comments to manipulate it.

提交回复
热议问题