JS Time Comparison sample sharing

Source: Internet
Author: User
Tags date1

  This article mainly introduces the JS time comparison example, the code is simple, after running can see the result, the need friend can refer to the following

    Code as follows: <html>  <head>   <script language= "javascript" type= "Text/javascript" >    /** Date comparison **/   function comparedate (strdate1,strdate2)    {    var date1 = NE W Date (Strdate1.replace (/-/g, "/"));     var date2 = new Date (Strdate2.replace (/-/g, "/"));     return date1-date2;   &NBSP      /** comparison **/   function Docompare () {    var strDate1 = Document.get Elementbyid ("StrDate1"). Value;     var strDate2 = document.getElementById ("StrDate2"). Value;     var result = Comparedate (STRDATE1,STRDATE2);     if (result>0) {     alert ("StrDate1 later than StrDate2");    }else if (result<0) {      alert ("strDate1 earlier than StrDate2");    }else if (result==0) {     alert ("strDate1 equals StrDate2");    }     &nbs P </script>  </head>  <body>   <input type= "text" id= "strDate1" name= "strDate1" value= "2012-07-01"/>   <input type= " Text "id=" StrDate2 "name=" StrDate2 "value=" 2012-08-01 "/>   <input type=" button "id=" Comparebtn "Name=" Comparebtn "value=" compares "onclick=" docompare (); />  </body> </html>  

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.