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

1 answer 1

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 
  • one
    You can use PyICU to not touch the global locale. - jfs
  • @jfs, thanks for PyICU! added an example in response ... - MaxU