Use JS to implement the countdown (date string as parameter)

Source: Internet
Author: User

<!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)

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.