I have this string '2015-04-08T07:52:00Z'
and I wanna to convert it to '08/04/2015'
, how can I do this?
Asked
Active
Viewed 8,633 times
7

Dyrandz Famador
- 4,499
- 5
- 25
- 40

Natali Torres
- 303
- 1
- 4
- 13
-
1[Date and Time Representation in Python](http://www.seehuhn.de/pages/pdate) – Dyrandz Famador Apr 17 '15 at 01:12
-
related: [How to parse ISO formatted date in python?](http://stackoverflow.com/q/127803/4279) – jfs May 09 '15 at 21:46
2 Answers
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')

Vorticity
- 4,582
- 4
- 32
- 49
-
That means clicking the check mark below the upside-down triangle on the left. – Registered User Apr 17 '15 at 01:32
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')

Raphael Amoedo
- 4,233
- 4
- 28
- 37
-
1you should probably use a single namespace e.g., `easy_date.string_to_string` (create a package and import the corresponding names, see how [`asyncio`](https://hg.python.org/cpython/file/9dfda4e7169a/Lib/asyncio/__init__.py) or `numpy` do it). – jfs May 09 '15 at 21:45