Home > Web Front-end > JS Tutorial > js only compares instances of time size

js only compares instances of time size

韦小宝
Release: 2018-01-17 10:39:55
Original
1386 people have browsed it

The following editor will bring you an example of js onlycomparing time size. The editor thinks it’s pretty good, so I’ll share the js source code with you now and give it as a reference. If you are interested in js, please follow the editor to take a look.

The examples are as follows:

<script> 
 ///比较函数 
 function compareTime(date1, date2) { 
  var d1_year, d1_month, d1_day, d1, time_span1, 
    d2_year, d2_month, d2_day, d2, time_span2; 
  d1_year = date1.getFullYear(); 
  d1_month = date1.getMonth() + 1; 
  d1_day = date1.getDate(); 
  d1 = new Date(d1_year, d1_month - 1, d1_day, 0, 0, 0); 
  time_span1 = date1.getTime() - d1.getTime(); 
  d2_year = date2.getFullYear(); 
  d2_month = date2.getMonth() + 1; 
  d2_day = date2.getDate(); 
  d2 = new Date(d2_year, d2_month - 1, d2_day, 0, 0, 0); 
  time_span2 = date2.getTime() - d2.getTime(); 
  return time_span1 - time_span2; 
 } 
 //测试 
 <SPAN style="COLOR: #99cc00"> var date1 = new Date(2017, 10, 21, 20, 20, 21); 
 var date2 = new Date(2016, 5, 2, 20, 20, 30); 
 alert(compareTime(date1, date2));</SPAN> 
</script>
Copy after login

The above js only compares the time size The examples are all the content shared by the editor. I hope it can give you a reference, and I hope you will support the PHP Chinese website.

Related recommendations:

Five steps to easily implement JavaScript HTML clock effect

A big analysis of the difference between JavaScript framework Angular and React

Template method singleton in javascript

The above is the detailed content of js only compares instances of time size. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template