A countdown looks like the simplest widget on the web: subtract two dates, show the difference. Then someone in Berlin asks why the "sale ends at midnight" timer says 6 hours on a site run from New York, and it stops being simple.
I built Flip Countdown, a free MIT flip-clock countdown (about 16 KB, no dependencies) for New Year, sales and launches. Here it is; press "Test the ending" to see what happens at zero:
Install
<script src="https://cdn.jsdelivr.net/npm/@fluritheme/countdown@1/dist/countdown.global.js" data-auto></script> import { createCountdown } from "@fluritheme/countdown"; createCountdown({ target: "2027-01-01T00:00:00", // no offset = each visitor's own midnight title: "New Year in", celebrate: "fireworks", // or "confetti" | "none" }); Two kinds of midnight
There are really two different questions a countdown can answer:
- "When does it happen for you?" New Year is at each person's own midnight. A target without an offset, like
2027-01-01T00:00:00, is read in the visitor's local time. - "When does it happen, full stop?" A sale that ends at midnight in Vienna ends at 18:00 in New York. For that you pass
timeZone: "Europe/Vienna".
The second case needs the offset of an arbitrary IANA zone at an arbitrary moment, which JavaScript doesn't give you directly. The trick is to ask Intl.DateTimeFormat for the wall-clock parts in that zone and compare them to UTC:
function zoneOffset(tz, at) { const parts = new Intl.DateTimeFormat("en-US", { timeZone: tz, hourCycle: "h23", year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit", second: "2-digit", }).formatToParts(new Date(at)); const get = (t) => Number(parts.find((p) => p.type === t).value); const asUTC = Date.UTC(get("year"), get("month") - 1, get("day"), get("hour"), get("minute"), get("second")); return asUTC - Math.floor(at / 1000) * 1000; } Then resolving "midnight in Vienna" is a guess plus one correction, so it stays right across daylight-saving changes:
const guess = Date.UTC(y, mo - 1, d, h, mi, s); const first = guess - zoneOffset(tz, guess); return guess - zoneOffset(tz, first); Strings that already carry Z or +01:00 skip all of this and go straight to Date.parse.
The flip
Each digit is four spans: the static top and bottom halves, plus two flaps that fold over. When a digit changes, the new top and old bottom stay put while the flaps carry the old top down and the new bottom into place:
spans[0].textContent = digit; // static top: new spans[1].textContent = old; // static bottom: old spans[2].textContent = old; // flap folding down: old top spans[3].textContent = digit; // flap landing: new bottom Tabular numbers keep the width steady, so nothing jumps. With prefers-reduced-motion the digits just change.
Small things that matter in production
- A top bar shouldn't cover your header. When the bar is fixed to the top, it adds its own height to the body's padding and restores it when closed.
- Evergreen mode.
mode: "evergreen"gives each visitor their own 30-minute timer (or whatever you set), remembered on their device, for "offer ends in" without a fake deadline that resets on reload. - At zero it can keep a message, hide itself or redirect, and fires a
fluri-countdown-endevent. - It's a
role="timer"with a readable label, so screen readers get "2 days, 4 hours" rather than a pile of digits.
It's one of the free, MIT-licensed packages behind Fluri, my collection of interactive website effects. If you run WordPress, Shopify or Wix there's a no-code version with live settings.
Have you been bitten by time zones in a countdown before? I'd love to hear the war stories.


