7

I have this string '2015-04-08T07:52:00Z' and I wanna to convert it to '08/04/2015', how can I do this?

2

2 Answers 2

10

You can use the datetime.datetime.strptime() function to create a datetime object, then datetime.datetime.strftime() to return your correctly formatted date like so:

from datetime import datetime
dt = datetime.strptime('2015-04-08T07:52:00Z', '%Y-%m-%dT%H:%M:%SZ')
print dt.strftime('%d/%m/%Y')
Sign up to request clarification or add additional context in comments.

1 Comment

That means clicking the check mark below the upside-down triangle on the left.
1

You can use easy_date to make it easy:

import date_converter
converted_date = date_converter.string_to_string('2015-04-08T07:52:00Z', '%Y-%m-%dT%H:%M:%SZ', '%d/%m/%Y')

1 Comment

you should probably use a single namespace e.g., easy_date.string_to_string (create a package and import the corresponding names, see how asyncio or numpy do it).

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.