Javascript countdown code

Source: Internet
Author: User

JS script: CopyCode The Code is as follows: <script language = "JavaScript" type = "text/JavaScript">
VaR integer = 1000;
Function showcountdown (year, month, day, divname ){
VaR now = new date ();
VaR enddate = new date (year, month-1, day, 14, 07 );
VaR lefttime = enddate. gettime ()-Now. gettime ();
VaR leftsecond = parseint (lefttime/1000 );
VaR day1 = math. Floor (leftsecond/(60*60*24 ));
VaR hour1 = math. Floor (leftsecond-day1*24*60*60)/3600 );
VaR hour = math. Floor (leftsecond-60*60)/3600 );
// If the hour is negative, 0 is displayed
If (hour> 0 ){
}
Else {
Hour = 0;
}
If (day1 <0 ){
Hour = hour1
}
VaR minute = math. Floor (leftsecond-day1*24*60*60-hour1*3600)/60 );
VaR second = math. Floor (leftsecond-day1*24x60*60-hour1 * 3600-minute * 60 );
VaR cc = Document. getelementbyid (divname );
// If the end time is negative, 0 is displayed.
If (lefttime> 0 ){
Cc. innerhtml = hour + "Hour" + minute + "Minute" + second + "second ";
// Cancel the comment if the year is displayed
// CC. innerhtml = "The distance from" + year + "year" + month + "month" + day + "also includes: "+ hour +" Hour "+ minute +" Minute "+ second +" second ";
}
Else {
Cc. innerhtml = 0 + "Hour" + 0 + "Minute" + 0 + "second ";
}
}
// Showdata is the ID of Div, and 10 indicates that the parameter is set based on your needs.
Window. setinterval (function () {showcountdown (2010, 8, 10, 'showdata') ;}, interval );
</SCRIPT>

Add the following code to the location where the time is to be displayed:Copy codeThe Code is as follows: <Div id = "showdata">
</Div>

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.