import datetime
# 按照时间顺序排列会话内容
chat_record = {'1':{'time':'2019-07-29 23:43:50', 'role':2},'2':{'time':'2020-07-29 23:43:51', 'role':2},'3':{'time':'2020-07-29 23:43:50', 'role':2}}
chat_key = chat_record.keys()
for temp in chat_key:
chat_record[temp]['time'] = datetime.datetime.strptime(chat_record[temp]['time'], '%Y-%m-%d %H:%M:%S').date()
chat_list = sorted(chat_record.items(), key = lambda item: item[1]['time'])
print(chat_list)