Js string date directly compare the size today met a bug, the project running for one year suddenly has a wrong date, and finally found that it is the reason for the direct comparison of string date.
The debugging result is as follows:
Many people say that js string dates can be directly compared and compared, which is more intelligent.
Alert ("2016-10-01"> "2016-10-02"); // false
// No matter whether js is compared by time format or string format, false is returned.
Therefore, we can compare
However, when the string date is not regular, for example:
Alert ("2016-10-4"> "2016-10-30"); // true
// Here js compares it as a string, so it cannot be directly compared and needs to be converted to the date format
Var date1 = new Date ("2016-10-4 ");
Var date2 = new Date ("2016-10-10 ");
Alert (date1> date2); // false
The same is true for string dates in yy/mm/dd format.