Dean Fogarty

Dean Fogarty

/ home / technical / svelte / timezones

Display the current date and time from multiple timezones.

Our goal?

We want to display the current time for a number of locations around the world as a table:

America/New_York Saturday, January 28, 2023 at 02:48:34
Europe/London Saturday, January 28, 2023 at 07:48:34
Asia/Tokyo Saturday, January 28, 2023 at 16:48:34
Australia/Brisbane Saturday, January 28, 2023 at 17:48:34


Create a component that periodically uses Date().toLocaleString() to format the current local time in arbitrary timezones and display as a table.

onMount / onDestroy

We can use Svelte’s lifecycle functions onMount() and onDestroy() to initialise and cleanup a periodic timer. The timer will get the date and update a reactive varible, which will redraw the table when changed.

The component

A single component fulfills our requirements (say ./TimeZoneTable.svelte):

    import { onMount, onDestroy } from 'svelte';

    export let timezones = [

    const locale = 'en-US';

    let now = new Date();
    let intervalId;

    onMount(() => {
        intervalId = setInterval(() => {
            now = new Date();
        }, 1000);

    onDestroy(() => {
        if (intervalId) {

    {#each timezones as z}
            <td>{now.toLocaleString(locale, { timeZone: z })</td>


Use the component wherever it’s required:

    import TimeZoneTable from './TimeZoneTable.svelte';

<TimeZoneTable />


We created a simple method for displaying the time in differen timezones around the world.

More information