I have this string '2015-04-08T07:52:00Z' and I wanna to convert it to '08/04/2015', how can I do this?
-
1Date and Time Representation in PythonDyrandz Famador– Dyrandz Famador2015-04-17 01:12:27 +00:00Commented Apr 17, 2015 at 1:12
-
related: How to parse ISO formatted date in python?jfs– jfs2015-05-09 21:46:32 +00:00Commented May 9, 2015 at 21:46
Add a comment
|
2 Answers
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')
1 Comment
Registered User
That means clicking the check mark below the upside-down triangle on the left.
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')