js test method for determining how many days a date is greater than

  • 2020-06-03 05:49:38
  • OfStack

This article describes the js detection method to determine how many days the date is greater than. Share to everybody for everybody reference. The specific analysis is as follows:

This example demonstrates how js can be used to compare local time (time on the visitor's computer, or standard time) based on the date in the tag span, such as 15 days off:

<!DOCTYPE html>
 <meta charset="utf-8" />
 <title> How to use js The test determines how many days the date is greater than </title>
 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?" Is greater than 15":" Less than 15");
 <ul id="time">
  <span>2014-07-05 08:52:32</span>

Hopefully, this article has been helpful in your javascript programming.

Related articles: