Going from twitter date to Python datetime date

前端 未结 10 1303
谎友^
谎友^ 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 09:55

    Using a similar strategy as SoFolichon proposed, in Python 3.x you can also use pytz like:

    from datetime import datetime, timezone
    import pytz
    
    datetime.strptime(tweets["created_at"], '%a %b %d %H:%M:%S %z %Y').replace(
    tzinfo=timezone.utc).astimezone(pytz.timezone('US/Eastern')).strftime(
    '%Y-%m-%d %H:%M:%S')
    

提交回复
热议问题