The method of simple time comparison of JS _javascript skill

Source: Internet
Author: User
Tags time and date

This example describes the JS simple time comparison method. Share to everyone for your reference, specific as follows:

Time comparison (YYYY-MM-DD) function comparedate (StartDate, EndDate) {var arrstart = Startdate.split ("-");
  var starttime = new Date (arrstart[0], arrstart[1], arrstart[2]);
  var starttimes = Starttime.gettime ();
  var arrend = Enddate.split ("-");
  var endtime = new Date (arrend[0], arrend[1], arrend[2]);
  var endtimes = Endtime.gettime ();
    if (endtimes<starttimes) {alert ("End time cannot be less than start time");
  return false;
return true; }//Time comparison (Yyyy-mm-dd HH:mm:ss) function Comparetime (starttime,endtime) {var starttimes = starttime.substring (0). spli
  T ('-');
  var endtimes = endtime.substring (0). Split ('-');
  StartTime = starttimes[1] + '-' + starttimes[2] + '-' + starttimes[0] + ' + starttime.substring (10, 19);
  Endtime = endtimes[1] + '-' + endtimes[2] + '-' + endtimes[0] + ' + endtime.substring (10, 19);
  var Thisresult = (Date.parse (endtime)-Date.parse (StartTime))/3600/1000; if (Thisresult < 0) {alert ("Endtime is less than tarttime!
  "); else if (Thisresult > 0){Alert ("Endtime is greater than tarttime!
  "); else if (Thisresult = 0) {alert ("Endtime equals tarttime!
  ");
  else {return ' exception ';

 }
}

PS: For JavaScript time and date operations interested friends can also refer to the site online tools:

Unix timestamp (timestamp) conversion tool:
Http://tools.jb51.net/code/unixtime

Online Worldwide Time query:
Http://tools.jb51.net/zhuanhuanqi/worldtime

Online Perpetual calendar:
Http://tools.jb51.net/bianmin/wannianli

Web calendar:
Http://tools.jb51.net/bianmin/webwannianli

More about JavaScript related content to view the site topics: "JavaScript time and date Operation skills Summary", "JavaScript switching effects and techniques summary", "JavaScript Search Algorithm Skills summary", " JavaScript animation effects and tips Summary, "JavaScript Error and debugging skills Summary", "JavaScript data structure and algorithm skills summary", "JavaScript traversal algorithm and Skills summary" and "JavaScript Mathematical operation Usage Summary"

I hope this article will help you with JavaScript programming.

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.