Dev Helpers
← Back

Time zone conversion board

Place this file at app/regions/[code]/page.tsx in an App Router project.

Open this example in the interactive library

Source code

// app/regions/[code]/page.tsx

import { notFound } from "next/navigation";

export default async function TimeZoneConversionBoard({
  params,
}: {
  params: Promise<{ code: string }>;
}) {
  const places = [
    {
      code: "ca",
      lang: "en-CA",
      currency: "CAD",
      zones: ["America/Toronto", "America/Vancouver"],
    },
    { code: "jp", lang: "ja-JP", currency: "JPY", zones: ["Asia/Tokyo"] },
  ];
  const { code } = await params;
  const place = places.find((p) => p.code === code);
  if (!place) notFound();
  return (
    <dl>
      {place.zones.map((zone) => (
        <div key={zone}>
          <dt>{zone}</dt>
          <dd>
            {new Intl.DateTimeFormat(place.lang, {
              timeZone: zone,
              timeStyle: "short",
            }).format(new Date("2028-06-01T15:00Z"))}
          </dd>
        </div>
      ))}
    </dl>
  );
}