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.
- Virtualization | A Machine Reference Model
- An Ultimate Guide to Git and Github
- Accessing Attributes and Methods in Python
- Finding the best fit rectangle that covers a given point
- How to Add Google Charts on a Webpage?
- Top 5 best Programming Languages for Artificial Intelligence field
- Why should you not Hack Facebook!
- Licenses and their management in Cloud Computing
- Different Software License models in Cloud Computing
- How to make Storage Partition on Cloud
- Data Analytics and its type
- Virtualization | VMware: Full Virtualization
- Privacy and Security in online social media
- Virtualization | Xen: Paravirtualization
- Tips for restarting career after a break
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.