Going from twitter date to Python datetime date

前端 未结 10 1294
谎友^
谎友^ 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:54

    The following code will print a nice date (local time) from a Twitter date (UTC).

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

提交回复
热议问题