0

How do i convert this datetime using python?

2017-10-16T08:27:16+0000

I tried to use strptime but getting ValueError: time data '2017-10-16T08:27:16+0000' does not match format 'The %d %B %Y at. %H:%M'

import datetime
datetime.datetime.strptime("2017-10-16T08:27:16+0000", "The %d %B %Y at. %H:%M")

'''
I want my output to look like this
The 16 october 2017 at. 08:27
'''
1
  • google strptime and strftime. Commented Jan 15, 2018 at 13:29

2 Answers 2

2

First parse the string correctly, then print it in the desired format:

import datetime
date = datetime.datetime.strptime("2017-10-16T08:27:16+0000", "%Y-%m-%dT%H:%M:%S%z")
print(date.strftime("The %d %B %Y at. %H:%M"))
Sign up to request clarification or add additional context in comments.

Comments

1

https://blogs.harvard.edu/rprasad/2011/09/21/python-string-to-a-datetime-object/ You have to first strip your date using strptime() and then rebuild it using strftime()

import datetime
time = "2017-10-16T08:27:16+0000"
stripedTime = datetime.datetime.strptime(time, '%Y-%m-%dT%I:%M:%S%z')

rebuildTime = stripedTime.strftime('The %d %B %Y at. %H:%M')
print(rebuildTime)

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.