Skip to content
Advertisement

Protractor: How to sort a list by date/time?

How do I sort a list by date/time? in my application, the date/time format is “Mon, Nov 1 | 8:30 PM” when I try to convert the string into date getting an invalid date as o/p. Help me to sort a list by date/time.

Related to this question

Advertisement

Answer

You can parse the strings to values that sort as required. If the year isn’t important, that makes it easier.

Convert the month to a number, convert hours to 24 hour time then pad to two digits so that for example “Mon, Nov 1 | 8:30 PM” becomes 11012030.

E.g.

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement