How do I convert from timestamp to date in python?

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

+6
source share
2 answers

You can use the datetime.datetime.strptime() function to create a datetime object, then datetime.datetime.strftime() to return the correct formatted date as follows:

 from datetime import datetime dt = datetime.strptime('2015-04-08T07:52:00Z', '%Y-%m-%dT%H:%M:%SZ') print dt.strftime('%d/%m/%Y') 
+8
source

You can use easy_date to simplify it:

 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
source

Source: https://habr.com/ru/post/985315/


All Articles