<!DOCTYPE HTML><HTML><Head> <MetaCharSet= "Utf-8"> <title>JS Implementation Countdown</title> <style> *{margin:0;padding:0;List-style:None;}Body{font-size:18px;text-align:Center;}. Time{Height:30px;padding:200px;} </style></Head><Body><Divclass= "Time"> <spanID= "Showinterval"></span></Div><Script> functionGetdistancetime (time,showinterval) {varEndTime= NewDate (Date.parse (Time.replace (/-/G,"/")));/*Replace replaces all '-' in the time string with '/', parse converts a time-formatted string into milliseconds*/ varNowtime= NewDate (); varDistance=endtime.gettime ()-nowtime.gettime ();/*gettime Converts a Date object to milliseconds*/ var Day= 0; varHour= 0; varminute= 0; varSecond= 0; if(Distance>= 0) { Day=Math.floor (Distance/ +/ -/ -/ -); Hour=Math.floor (Distance/ +/ -/60%24);minute=Math.floor (Distance/ +/ -% -); Second=Math.floor (Distance/1000%60); }Else{alert ("The target date is less than the current date!")} document.getElementById (Showinterval). InnerHTML= Day+ "days" +Hour+ "when" +minute+ "points" +Second+ "seconds"; }//setinterval (function () {getdistancetime (' 2016/05/19 12:00:00 ', ' showinterval ');},0);SetInterval (function() {Getdistancetime ('2017-05-19 12:00:00','Showinterval');},0);</Script></Body></HTML>
The passed-in date parameter format can also be ' 2017/05/19 12:00:00 '
The effect is as follows:
Use JS to implement the countdown (date string as parameter)