Home > Web Front-end > JS Tutorial > js method to detect and determine how many days a date is greater than

js method to detect and determine how many days a date is greater than

PHPz
Release: 2018-10-15 15:00:26
Original
2096 people have browsed it

This article mainly introduces the method of js detection to determine how many days a date is greater than, and involves the related skills of javascript operating dates. It has certain reference value. Friends in need can refer to

This example demonstrates how to use it. js compares the local time (the time on the visitor's computer, or standard time) based on the date in the tag span, such as a difference of 15 days:

<!DOCTYPE html>
<html>
<head>
 <meta charset="utf-8" />
 <title>如何用js检测判断日期大于多少天</title>
 <script>
 window.onload=function(){
 var ul1=document.getElementById("time");
 var span1=ul1.getElementsByTagName("span");
 var data=span1[0].innerHTML;
    var a = data.split(" ");
    var b = a[0].split("-");
    var c = a[1].split(":");
    var oldTime = new Date(b[0], b[1]-1, b[2], c[0], c[1], c[2]);
 var nowTime=new Date();
 document.write((nowTime-oldTime)/(1000*60*60*24)>15?"大于15":"小于15");
 }
 </script>
</head>
<body>
 <ul id="time">
 <li>
  <span>2014-07-05 08:52:32</span>
 </li>
 </ul>
</body>
</html>
Copy after login

[Related tutorials Recommended】

1. JavaScript video tutorial
2. JavaScript online manual
3. bootstrap tutorial

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