The JavaScript web page implements a countdown program to calculate the time remaining in the current year, and the javascript countdown

Source: Internet
Author: User

The JavaScript web page implements a countdown program to calculate the time remaining in the current year, and the javascript countdown

I saw an error in this program on the Internet and corrected it here:

Function counter () {var date = new Date (); var year = date. getFullYear (); var date2 = new Date (year, 11, 30, 23, 59, 59);/* convert to seconds */var time = (date2-date) /1000; var day = Math. floor (time/(24*60*60) var hour = Math. floor (time % (24*60*60)/(60*60) var minute = Math. floor (time % (24*60*60) % (60*60)/60); var second = Math. floor (time % (24*60*60) % (60*60) % 60 ); var str = year + "years remaining" + day + "day" + hour + "hour" + minute + "minute" + second + "second"; console. log (str);} window. setInterval ("counter ()", 1000 );

I wrote this myself.

Var oDateNow = new Date (); var oYear = oDateNow. getFullYear (); var oDateEnd = new Date (); oDateEnd. setFullYear (oYear + 1); oDateEnd. setMonth (0); oDateEnd. setDate (0); oDateEnd. setHours (0); oDateEnd. setMinutes (0); oDateEnd. setSeconds (0); function upDate () {var oDateNow = new Date (); var iTime = oDateEnd. getTime ()-oDateNow. getTime (); var iRemain = iTime/1000; var iDay = parseInt (iRemain/86400); iRemain % = 86400; var iHour = parseInt (iRemain/3600 ); iRemain % = 3600; var iMin = parseInt (iRemain/60); iRemain % = 60; var iSec = parseInt (iRemain); document. write (oYear + "years left" + iDay + "day" + iHour + "Hour" + iMin + "Minute" + iSec + "second ");} setInterval (function () {upDate ()}, 1000 );

The seconds of these two methods are sourced

The above section describes how to implement a countdown program to calculate the time remaining in the current year on the JavaScript web page. I hope it will help you. If you have any questions, please leave a message, the editor will reply to you in a timely manner. Thank you very much for your support for the help House website!

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.