A countdown timer is an accurate timer that can be used for a website or blog to display the count down to any special event, such as a birthday or anniversary.
Basics of a countdown timer are :
- Set a valid end date.
- Calculate the time remaining.
- Convert the time to a usable format.
- Output the clock data as a reusable object.
- Display the clock on the page, and stop the clock when it reaches zero.
Step 1 : Set a Valid End Date
Step 2 : Calculate Remaining Time
First we calculate the time remaining by subtracting the deadline by current date and time then we calculate the number of days,hours,minutes and seconds.The Math.floor() function is used to return the largest integer less than or equal to a given number.
Step 3 : Output the result
In the code below the result is given as output by id=”demo”
Step 4 : Write some text if the countdown is over
If the countdown timer is over then “expired” will be displayed on the screen.
When the Countdown Timer session is exceeded,the following output would be displayed:
Applications of Countdown Timer
- Used during Events to display the time left for its commencement.
- Used by online commerce websites to display time left for an ongoing sale.
- Used by websites during promotions
- Used in Car racing games,football games etc
- Used in Auction Websites to display the left for placing bids.
- The code will be lightweight because it will have zero dependencies.
- The website will perform better because there won’t be any need of loading external scripts and style sheets.
- The user gets more control because he has built the clock to behave exactly the way he wants it to rather than trying to bend a plugin according to his will.
This article is contributed by Shubrodeep Banerjee. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Timer in C++ using system calls
- Algorithm for Dynamic Time out timer Calculation
- Create an unordered list without any bullets using CSS
- Create a column using for loop in Pandas Dataframe
- How to create hidden form element on the fly using jQuery ?
- Create a GeeksforGeeks Wrapper Application using Electron
- How to Create a Custom Image Magnifier using jQuery ?
- How to create a Stopwatch App using Android Studio
- How to create and deploy your portfolio in under 10 minutes
- Python program to create Bankaccount class with deposit, withdraw function
- Python | Create a Pandas Dataframe from a dict of equal length lists
- 10 Ways to Create a Stream in Java
- How to create an unordered_map of pairs in C++?
- How to create an array with key value pairs in PHP?
- Steps to Create and Publish NPM packages
- Python Program to create an OTP by squaring and concatenating the odd digits of a number
- How to create a Class in JShell of Java 9
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.