Small, standalone demo showing how to use the Swatch Internet Time API. This demo is intentionally minimal and uses vanilla JavaScript + Bootstrap so it's easy to copy and adapt.
Endpoint: https://api.swatchtime.online/api/v1/current
- The demo shows a set of selectable
fieldsthat are sent as a comma-separatedfieldsquery parameter to the API. - The rendered
?fields=text input element is read-only and updates as you check/uncheck boxes. - Click the green Fetch API data button to retrieve data.
- The "Sample code to fetch API data" shows the exact query that is being sent to the API.
- The sample fetch code demonstrates a robust pattern: it checks
resp.ok, returnsresp.json()and includes a.catch()handler for errors. - The Copy button copies the snippet to the clipboard and shows a short Bootstrap toast confirmation.
- The demo will display the raw JSON and a parsed, friendly view.
-
Open
index.htmlin a browser. -
Or, run via a simple static web server:
python3 -m http.server 8000
# then load http://localhost:8000/swatch-api-demo in your browserswatch: string — beats with two-decimal centibeat precision (e.g. "123.45").whole: string — floored integer part of beats, zero-padded to 3 digits (e.g. "005", "123").rounded: string — nearest-integer beat, wrapped modulo 1000, zero-padded to 3 digits (e.g. 999.6 -> "000").time24(BMT): string — 24-hour time derived from Biel Mean Time (e.g. "16:50:24").time12(BMT): string — 12-hour time derived from Biel Mean Time (e.g. "04:50:24").ampm(BMT): string — "AM" or "PM" for thetime12field.date(BMT): string — Biel date inYYYY-MM-DD(e.g. "2025-11-27").
When producing the swatch field with centibeat precision, implementors must avoid displaying 1000.00. This can happen if the raw beat (e.g. 999.995) is rounded to two decimals before wrapping. Use the following safe pattern:
const rawBeats = bielSeconds / 86.4;
let rounded = Math.round(rawBeats * 100) / 100;
if (rounded >= 1000) rounded = rounded - 1000;
const swatch = rounded.toFixed(2);This keeps user-friendly rounding and ensures the beat display stays within 0.00–999.99.
timestamp: string — ISO-8601 UTC instant (e.g.2025-11-27T15:50:24.851Z) — use this for unambiguous UTC comparisons.
- BMT (Biel Mean Time): the API's human-readable date/time fields (
time24,time12,ampm,date) are presented in BMT — a canonical fixed offset of UTC+1 with no DST. - Canonical computation (how
swatchis derived):- Compute seconds since UTC midnight including milliseconds.
- Add
3600seconds (fixed offset for BMT) and wrap modulo86400. - Divide by
86.4(seconds per beat) to get beats. swatchis the beats value formatted to two decimals (centibeats).wholeis the floored integer part of beats (zero-padded to 3 digits).roundedis the nearest integer of beats, then wrapped modulo 1000 and zero-padded to 3 digits.
- Prefer
timestampwhen you need UTC or when comparing events across timezones. date,time24, andtime12are conveniences derived from the same Biel instant used to computeswatch, so they match the beat value.