Sort string array containing time in format '09:00 AM'?

后端 未结 5 919
面向向阳花
面向向阳花 2020-12-17 09:45

I am trying to sort my array.

The array consists of data in time format.

Array:

\'9:15 AM\', \'10:20 AM\', \'02:15 PM\'

How

5条回答
  •  执笔经年
    2020-12-17 10:40

    Implement the sort(compare) function and compare the date string using any arbitrary date :

    Array.sort(function (a, b) {
        return Date.parse('01/01/2013 '+a) - Date.parse('01/01/2013 '+b)
    });
    

    01/01/2013 is any arbitrary date.

提交回复
热议问题