Dev Helpers
← Back

Live local clock

Import and render <LiveLocalClock /> in a React project.

Open this example in the interactive library

Live preview

Source code

// components/LiveLocalClock.tsx

import { useState, useEffect } from "react";

export default function LiveLocalClock({
  iso = "2027-03-14T15:30:00Z",
}: { iso?: string } = {}) {
  const [now, set] = useState(iso);
  useEffect(() => {
    const tick = () => set(new Date().toISOString());
    tick();
    const timer = setInterval(tick, 1000);
    return () => clearInterval(timer);
  }, []);
  return <time dateTime={now}>{now.slice(11, 19)} UTC</time>;
}