老铁们,在列表中如何对时间进行排序~

fx  = [{'次数': 2, '时间': '10:45:00'}, {'次数': 4, '时间': '14:58:00'}, {'次数': 5, '时间': '09:59:00'}, {'次数': 28, '时间': '08:13:00'}, {'次数': 34, '时间': '08:28:00'}, {'次数': 4, '时间': '05:12:00'}, {'次数': 12, '时间': '04:56:00'}]

上面的这个列表中,进行时间上的排列,比如最后那个是4点56的,排在第一位,9点59的那个排在最后面。

老铁们,帮帮忙啊~~谢谢

阅读 4.2k
3 个回答
fx.sort(key=lambda item: int(item['时间'][:2])*60 + int(item['时间'][3:5]))

取出来时间,desc

    fx.sort(function (pre, next) {
        return new Date('1970/01/01 ' + pre['时间']) - new Date('1970/01/01 ' + next['时间'])
    });
    console.log(JSON.stringify(fx))
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题