Skip to content
Advertisement

Python count down timer for date, hour, minute and second

In this link on the second example i found a count down timer, but it only works for minutes and seconds, how can i make it work for hours and days too. This is the code

JavaScript

Advertisement

Answer

First things first:

Using .sleep() as a timer is not a good idea. Sleep() doesn’t take into consideration the time necessary to run the code. So what you’re in reality getting is not one second but code execution time + .sleep() + code execution time. This means that if send this code to someone it will calculate differently based on how fast their machine can execute the code.

If you’re interested in making precise content take a look at this and this thread.


As for our question you simply need to format the output:

JavaScript

Here is a small demonstration of the problem these small differences will add up if you’re measuring a long period of time.

JavaScript

output:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement