Source Code

<div class="mtz-wrap" id="mtzWrap"></div>

Multi-Timezone Digital Clock — Free HTML CSS JS Snippet

Multi-Timezone Digital Clock · Dashboards · Plain HTML, CSS & JS · Live preview

What's included

Features

Live per-city clocks driven entirely by Intl.DateTimeFormat with an explicit timeZone option — no manual UTC offset math
Automatically correct across daylight saving time transitions, since the browser's timezone database handles it
Separate date string per city alongside the time, also timezone-correct
Day/night indicator icon (sun/moon) computed from each city's own local hour, independent of the viewer's timezone
Visually distinct dark card styling applied automatically to cities currently in their night hours
Single shared setInterval tick updates all city cards from one Date instance each second
Cards generated dynamically from a simple CITIES array — easy to add or remove cities
Tabular-numeral time display to avoid digit-width jitter as seconds tick over

About this UI Snippet

Multi-Timezone Digital Clock — Live City Clocks Using Intl.DateTimeFormat

Screenshot of the Multi-Timezone Digital Clock snippet rendered live

Showing the correct current time for several cities at once is a common dashboard need — for distributed teams, trading desks, or travel tools — and it's easy to get wrong by hand-rolling UTC offset math, which breaks around daylight saving time transitions. This snippet instead lets the browser's built-in Intl.DateTimeFormat API do all timezone conversion.

One shared JS Date, formatted per timezone

Only a single new Date() is created per tick, representing the current moment in UTC internally. Each city then gets its own pre-built Intl.DateTimeFormat instance constructed with an explicit timeZone option (e.g. 'America/New_York', 'Asia/Tokyo') — calling .format(now) on that formatter converts the same underlying instant into that timezone's local wall-clock time correctly, including automatically handling daylight saving time, without any manual offset arithmetic anywhere in the code.

Separate formatters for time, date, and the day/night check

Three formatters are built per city up front: one for the visible time string, one for the visible date string, and a third, minimal hour: 'numeric', hour12: false formatter used only to extract that city's current local hour as a number for the day/night logic — reusing Intl.DateTimeFormat even for that internal calculation rather than parsing the display string or computing an offset by hand.

A day/night icon driven by the extracted local hour

isNightHour() treats any local hour before 6 or from 18 onward as night. Because the hour figure comes from a real timezone-aware formatter rather than the viewer's own local time, a city on the other side of the world correctly shows a moon icon and a darker card background even while the visiting browser's own clock says midday.

A single interval keeps every card in sync

One setInterval(update, 1000) re-renders every card each second from one fresh Date, so all cities' clocks always reflect literally the same instant, just displayed through a different timezone-aware formatter.

Step by step

How to Use

  1. 1
    Load the snippetClick "Multi-Timezone Digital Clock" in the sidebar to load its HTML, CSS, and JS into the editor panels. The preview updates instantly.
  2. 2
    Edit the codeModify any panel — HTML, CSS, or JS. The preview refreshes as you type. Use Reset in each panel header to restore the original.
  3. 3
    Preview on devicesClick the Mobile (375px), Tablet (768px), or Desktop buttons in the preview header to check responsiveness.
  4. 4
    Export in your formatClick "HTML" to download a standalone file, "JSX" for a React component, "Tailwind" for a React + Tailwind CSS component, "Tailwind HTML" for a standalone HTML file with Tailwind CDN, "Vue" for a Vue 3 SFC with <template>/<script setup>/<style scoped>, or "Angular" for a standalone Angular .component.ts file. "Copy all" copies the full code to clipboard.
  5. 5
    Save your versionClick "Save as", type a name, and press Enter. Your snippet saves to IndexedDB and appears in the Saved tab.

Real-world uses

Common Use Cases

Distributed team and remote-work dashboards
Show teammates in different offices the current local time for each city at a glance.
Travel, scheduling, and meeting-planning tools
Help users pick meeting times that work across multiple timezones.
Reference for correct Intl.DateTimeFormat timezone usage
A clean example of timezone-safe formatting to copy into any project instead of manual offset math.
Teaching Intl.DateTimeFormat over hand-rolled timezone math
Demonstrates why the built-in Intl API is the right tool instead of manually adding UTC offsets.

Got questions?

Frequently Asked Questions

Manual offset math breaks around daylight saving time transitions, since offsets change twice a year in many regions and vary by exact date. Intl.DateTimeFormat, given an explicit timeZone like 'America/New_York', uses the browser's built-in timezone database to always compute the correct local time automatically.

A dedicated Intl.DateTimeFormat instance per city (configured with hour: 'numeric', hour12: false) extracts that city's current local hour as a number. Any hour before 6 or from 18 onward is treated as night, independent of what time it is for the person viewing the page.

Yes — because all conversion goes through Intl.DateTimeFormat with a named IANA timezone rather than a fixed numeric offset, daylight saving transitions in any of the listed cities are handled automatically by the browser's timezone database.

Yes — add an entry to the CITIES array with a display name and a valid IANA timezone string (e.g. 'Asia/Kolkata'), and buildCards()/update() will automatically render and keep a new card in sync for it.