jquery Calculates the time difference (days, hours, minutes, seconds) and uses the timer to get

Source: Internet
Author: User

Similar to the site snapping demand, there will be a time countdown display (days, hours, minutes, seconds)

To get the final time compared to the current time, calculate the difference and execute it in seconds with the timer

Implementation code:

$ (document). Ready (function () {run (enddate);});//Timerfunction Run (enddate) {//if EndDate is the date type passed in in the background, this translates directly to the number of millisecondsEnddate=NewDate (Eddate.replace ("T", ""). GetTime ()); //executes at 500 milliseconds (avoids slow execution of the method, which can affect the presentation) 0var time = 500; SetInterval ("Datedif ('" +enddate+ "')", time);}//Calculation Time Differencefunction Datedif (enddate) {var date= EndDate-NewDate (). GetTime (); var days= Date/1000/60/60/24; var daysround=Math.floor (days); var hours= DATE/1000/60/60-(24 *daysround); var hoursround=Math.floor (hours); var minutes= DATE/1000/60-(* * daysround)-(60 *hoursround); var minutesround=Math.floor (minutes); var seconds= date/1000-(* * * daysround)-(60 * hoursround)-minutesround); var secondsround=Math.floor (seconds); var time= "Countdown" + (daysround+ "Day" +hoursround + "+minutesround+" minute "+secondsround+" seconds "); $("#ytime"). Text (time); } 

You will get a similar effect as follows:

jquery Calculates the time difference (days, hours, minutes, seconds) and uses the timer to get

Related Article

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.