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 firstname.lastname@example.org. 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
- Hackathon - Think, Code, Create
- How to create an unordered_map of pairs in C++?
- How to create an array with key value pairs in PHP?
- How and Why To Create an SQL Database on Azure
- How to create and deploy your portfolio in under 10 minutes
- How to create a Folder without any name and icon in Windows OS?
- Create an unordered list without any bullets using CSS
- 10 Ways to Create a Stream in Java
- Create a Virtual Machine and Set up API on Google Cloud
- Create a column using for loop in Pandas Dataframe
- How to create a Shared Folder between two Local User in Linux?
- Python | Create a Pandas Dataframe from a dict of equal length lists
- Python program to create Bankaccount class with deposit, withdraw function
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 Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.