Countdown to Date
Count down the days, hours, minutes and seconds until any date and time, with a shareable link and correct handling of time zones and clock changes.
Why a naive timer runs slow
setInterval does not fire on a fixed schedule. It waits the requested delay
after the previous callback returns, so any lateness — timer resolution, a busy page,
a slow callback — is carried into every subsequent tick rather than corrected. Measured
against a perfect schedule:
| Interval | Late per tick | Ticks per hour | Drift per hour |
|---|---|---|---|
| every 10 ms | 0.40 ms | 360,000 | 144 seconds |
| every 20 ms | 0.54 ms | 180,000 | 97 seconds |
| every 50 ms | 0.50 ms | 72,000 | 36 seconds |
The lateness per tick is roughly constant, so the total error grows with the number of ticks rather than with elapsed time — which means a faster timer drifts further, not less. The hourly column is arithmetic on a few seconds of measurement rather than an hour-long run, but the per-tick figure it rests on is measured.
The fix is to stop asking “how long until the next one”
Keep the start time. Before each tick, work out when tick n+1 is supposed to happen and wait exactly that long from now. A late tick then shortens the next delay instead of pushing it:
const target = start + (n + 1) * period;
setTimeout(tick, Math.max(0, target - performance.now())); Measured the same way, accumulated error over 200 ticks falls from 80.2 ms to under 0.4 ms. The individual ticks are no more punctual — they still land late by whatever the event loop costs — but the error stops compounding, which is the part that matters for a clock.
The same reasoning applies to the countdown itself: show the remaining time by subtracting now from a fixed end timestamp, rather than by taking a second off a running total each tick. Then the display is right even if the tab was backgrounded, the timer was throttled, or the machine went to sleep — because it never depended on the ticks arriving at all.
How to use
- Set your target date and time.
- Add a title for what you are counting down to.
- Copy the link to share the countdown.
- Check the target's time zone if sharing across regions.
Frequently asked questions
Does the countdown keep running if I close the tab?
The display stops, but nothing is lost — the countdown is calculated from the target date each time the page loads rather than counted down in the background. Reopening it shows the correct remaining time.
What happens across a daylight saving change?
The count adjusts, because it is computed from the difference between two actual moments rather than by subtracting a fixed number of hours. A countdown spanning a clock change will be an hour different from a naive calculation, and correctly so.
Will it show the same time for everyone?
Only if the target is anchored to a specific time zone. Otherwise each viewer sees the countdown to that clock time in their own zone, which is different for each of them. For an event happening at one moment worldwide, the zone has to be part of the target.
Is this accurate to the second?
As accurate as your device's clock, which is normally synchronised to within a fraction of a second. The display updates roughly every second, so the final moments may appear to skip slightly if the browser tab is inactive.
Can I count down to something in the past?
It will show elapsed time instead, which is useful for tracking how long since something happened. The arithmetic is the same in both directions; only the sign changes.
Does the shared link expose anything?
Only the target date and title, which are encoded in the link itself. Nothing is stored on a server, so a countdown exists only in the link you share.
🔒 This tool runs entirely in your browser. Nothing you enter is uploaded, logged, or stored.