Javascript time comparison implementation code _ time date

Source: Internet
Author: User
In web development, you sometimes need to compare the time (mainly the start time and end time) in the input box. After searching on the Internet, it is found that many of them are invalid, the following methods have been verified by the younger brother. In web development, you sometimes need to compare the time (mainly the start time and end time) in the input box. After searching on the Internet, it is found that many of them are invalid, the following methods have been verified by the younger brother. (Please pay attention to the red part)

Function ValidtorTime (){

Var d1 = new Date (document. getElementById ('txbfromdate ') . Value. replace (/\-/g ,"\/"));
Var d2 = new Date (document. getElementById ('txbtodate ') . Value. replace (/\-/g ,"\/"));
If (d1> d2)
{
Alert ("the end time must be after the start time! ");
Return false;
}
Return true;
}

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.