Today, a bug was encountered, the project of running a year was wrong, and the last discovery was the reason for the direct comparison of the string date.
To debug the results directly below:
Many people say JS string date can be directly compared, more intelligent
Alert ("2016-10-01" > "2016-10-02");//false
Whether JS is a time format or a string format comparison, the return is False
So you can compare
But when the string date is not normal, for example:
Alert ("2016-10-4" > "2016-10-30");//true
Here JS is to compare it as a string, so it cannot be directly compared, it needs to be converted into a date format
var date1 = new Date ("2016-10-4");
var date2 = new Date ("2016-10-10");
Alert (date1> date2);//false
The string date in the YY/MM/DD format is the same.
This article is from the "10143615" blog, please be sure to keep this source http://10153615.blog.51cto.com/10143615/1878811
JS String Date Direct comparison size