0

I got "timestamp": "2018-10-28T12:49:00.816Z" from a API response. How can I convert 2018-10-28T12:49:00.816Z to %Y-%m-%d %H:%M:%S format.I tried datetime.strptime

1 Answer 1

4

This is suprisingly easy using dateutil

import dateutil

dateutil.parser.parse("2018-10-28T12:49:00.816Z")

output:

datetime.datetime(2018, 10, 28, 12, 49, 0, 816000, tzinfo=tzlocal())

or directly to your format:

dateutil.parser.parse("2018-10-28T12:49:00.816Z").strftime('%Y-%m-%d %H:%M:%S')

output:

 '2018-10-28 12:49:00'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.