JS date comparison size, JS judge whether the date in the interval, JS determine whether the time period in another time period

Source: Internet
Author: User

    /** Date Parsing, string to date * @param datestring can return the corresponding Date object for 2017-02-16,2017/02/16,2017.02.16 * @returns {date} */      functionDateparse (datestring) {varSeparator_bar = "-"; varSeparator_slash = "/"; varSeparator_dot = "."; varDatearray; if(Datestring.indexof (Separator_bar) >-1) {Datearray=Datestring.split (Separator_bar); }Else if(Datestring.indexof (Separator_slash) >-1) {Datearray=Datestring.split (Separator_slash); }Else{Datearray=Datestring.split (SEPARATOR_DOT); }          return NewDate (Datearray[0], datearray[1]-1, datearray[2]);            }; /** * Date Comparison size * comparedatestring greater than datestring, return 1; * equals return 0; * comparedatestring less than datestring, return-1 * Date @param datestring Date * @param comparedatestring comparison*/      functionDatecompare (datestring, comparedatestring) {if(IsEmpty (datestring)) {alert ("DateString cannot be empty"); return; }          if(IsEmpty (comparedatestring)) {alert ("Comparedatestring cannot be empty"); return; }          varDateTime =Dateparse (datestring). GetTime (); varComparedatetime =Dateparse (comparedatestring). GetTime (); if(Comparedatetime >dateTime) {              return1; }Else if(Comparedatetime = =dateTime) {              return0; }Else{              return-1;            }      }; /** * To determine if the date is within the range , returns true within the interval, no return false * @param datestring Date String * @param startdatestring interval start date String * @param enddatestring interval End Date String * @returns {number}*/      functionIsdatebetween (datestring, startdatestring, enddatestring) {if(IsEmpty (datestring)) {alert ("DateString cannot be empty"); return; }          if(IsEmpty (startdatestring)) {alert ("Startdatestring cannot be empty"); return; }          if(IsEmpty (enddatestring)) {alert ("Enddatestring cannot be empty"); return; }          varFlag =false; varStartflag = (Datecompare (datestring, startdatestring) < 1); varEndflag = (Datecompare (datestring, enddatestring) >-1); if(Startflag &&Endflag) {Flag=true; }          returnFlag;            }; /** * Determine if the date range [startdatecomparestring,enddatecomparestring] is completely within another date range [startdatestring,enddatestring] * i.e. [start  Datestring,enddatestring] interval is completely inclusive of [startdatecomparestring,enddatecomparestring] interval * Returns true in the interval, no return false * @param Startdatestring the start date of the new selection, such as the start date of the input box * @param enddatestring the end date of the new selection, such as the end date of the input box * @param startdatecomparestring comparison Start Date * @param enddatecomparestring comparison End date * @returns {Boolean}*/      functionIsdatesbetween (startdatestring, enddatestring, startdatecomparestring, enddatecomparestring) { /c3>if(IsEmpty (startdatestring)) {alert ("Startdatestring cannot be empty"); return; }          if(IsEmpty (enddatestring)) {alert ("Enddatestring cannot be empty"); return; }          if(IsEmpty (startdatecomparestring)) {alert ("Startdatecomparestring cannot be empty"); return; }          if(IsEmpty (enddatecomparestring)) {alert ("Enddatecomparestring cannot be empty"); return; }          varFlag =false; varStartflag = (Datecompare (startdatecomparestring, startdatestring) < 1); varEndflag = (Datecompare (enddatecomparestring, enddatestring) >-1); if(Startflag &&Endflag) {Flag=true; }          returnFlag; };</span>

JS date comparison size, JS judge whether the date in the interval, JS determine whether the time period in another time period

JS to determine whether the time interval in another time interval, JS time format, JS time comparison size

JS date comparison size, JS judge whether the date in the interval, JS determine whether the time period in another time period

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.