JS String Date Direct comparison size

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.