Going from twitter date to Python datetime date

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

    Twitter API V2 sends date strings that look like this:

    2020-12-15T20:17:10.000Z

    This worked, to convert from string to datetime:

    datetime.datetime.strptime(THE_STRING,"%Y-%m-%dT%H:%M:%S.%fZ")
    

    The end looks like a timezone, but it's milliseconds, hence the %f. The final character, "Z" is a timezone code that means UTC, as explained, here.

提交回复
热议问题