Good day to all! Please tell me how to convert the received date. I get a date from a JSON object in a format (2017-01-29 09:00:00) how do I convert it to (01/29 Sun 09:00)?
Thanks in advance
It is possible so:
In [12]: s = '2017-01-29 09:00:00' In [13]: import datetime In [14]: datetime.datetime.strptime(s, '%Y-%m-%d %H:%M:%S').strftime('%m/%d %a %H:%M') Out[14]: '01/29 Sun 09:00' PS I have English system settings, so - Sun
UPDATE: thanks @jfs for the advice on using PyICU , which allows you to dynamically change the locale in the program, without touching the system settings:
import datetime import icu s = '2017-01-29 09:00:00' df = icu.SimpleDateFormat('MM/dd eee HH:mm', icu.Locale('ru')) d = datetime.datetime.strptime(s, '%Y-%m-%d %H:%M:%S') print(df.format(d)) Result:
01/29 вс 09:00 Source: https://ru.stackoverflow.com/questions/618888/
All Articles
2017-01-29 09:00:00is a string or adatetimeobject? - MaxU