1.字符串时间转换为可使用时间
rds_baktime = "2021/12/23 9:32:07"
str_baktime = rds_baktime.replace('\n', '').replace('\r', '')
date_baktime = datetime.datetime.strptime(str_baktime,'%Y/%m/%d %H:%M:%S')
print(date_baktime)
2.给时间排序
list=["2018-06-01 14:54:34","2018-06-01 14:55:02","2018-06-01 15:55:02","2018-06-01 14:55:01"]
def get_list(date):
return datetime.datetime.strptime(date,"%Y-%m-%d %H:%M:%S").timestamp()
list=sorted(list,key=lambda date:get_list(date))
print(list)