NewAPIVerve Academy: free courses and certifications anyone can verify.Explore the Academy →

World Clock Template

  • Next.js
  • TypeScript

Live clocks for the cities you work with: local time, timezone and how far ahead or behind you they are.

A Next.js world clock. Add any city and it gets a ticking analog clock, the local time, its timezone and the difference from your own time, with dark cards for cities where it’s night. Your list is saved in the browser. Use it as a team dashboard for a distributed company, or lift the API route to show local times anywhere in your own app.

The world clock app running

What it does

Ticking analog clocks
Each city gets a drawn clock face and a digital time that update every second, with no extra API calls.
Day and night at a glance
Cards turn dark between 7pm and 6am local time, so you can see who is likely awake.
Hours from you
Shows how far ahead or behind each city is, including half-hour zones, and whether it’s already tomorrow there.
Picks the right London
When a name matches several places, the app asks which one, and remembers the choice.
Keeps your key private
The page only calls your own API route, which caches each city for an hour and limits each visitor to 10 lookups a minute.

How it works

The API route: it checks the city, calls World Time and returns every match.

app/api/time/route.ts
export async function GET(request: Request) {
  const city = str(new URL(request.url).searchParams.get('city'), 80);
  if (!city) return fail('Enter a city');

  const key = `time:${city.toLowerCase()}`;
  const hit = fromCache(key, TTL_MS);
  if (hit) return Response.json(hit);

  const blocked = guard(request);
  if (blocked) return blocked;

  return respond(async () => {
    const data = await callApi<{ foundCities: City[] }>('worldtime', { query: { city } });
    if (!data.foundCities?.length) throw Object.assign(new Error(`No city called “${city}” found`), { status: 404 });
    // Several places can share a name (London, Ontario and London, England), so return them all.
    const matches = data.foundCities.map((c) => ({
      city: c.city,
      country: c.country,
      region: c.province,
      timezone: c.timezone,
      utcOffset: c.utc_offset,
      abbreviation: c.dst_name || null
    }));
    toCache(key, { matches });
    return { matches };
  });
}

See the whole file on GitHub →

Deploy it

  1. Get a free API key

    The free plan includes 200 credits a month, no card needed. Create your key.

  2. Deploy it

    Click Deploy to Vercel. Vercel copies the repo to your GitHub account and asks for APIVERVE_API_KEY: paste your key there.

  3. Open your app

    Vercel builds it and gives you a live URL, usually in about a minute. Every push to the repo redeploys it.

Try the World Time API — the call this template makes

Request
GETapi.apiverve.com/v1/worldtime?city=San%20Francisco
Query parameters
Verification
Format

No key required to try it. Get a key to use it in your app.

Example
{
  "status": "ok",
  "error": null,
  "data": {
    "search": "San Francisco",
    "foundCities": [
      {
        "city": "San Francisco",
        "city_ascii": "San Francisco",
        "country": "Argentina",
        "iso2": "AR",
        "iso3": "ARG",
        "province": "Córdoba",
        "timezone": "America/Argentina/Cordoba",
        "time": "17:51",
        "time24": "17:51:13",
        "time12": "05:51:13 PM",
        "date": "2026-10-26",
        "day": "Monday",
        "month": "October",
        "year": "2026",
        "unix": "1793047873",
        "dst": false,
        "dst_start": null,
        "dst_end": null,
        "dst_name": "-03",
        "utc_offset": "-03:00",
        "datetime": "2026-10-26T17:51:13-03:00",
        "utc_datetime": "2026-10-26T20:51:13Z",
        "day_of_year": 299,
        "week_number": 44
      },
      {
        "city": "San Francisco",
        "city_ascii": "San Francisco",
        "country": "United States of America",
        "iso2": "US",
        "iso3": "USA",
        "province": "California",
        "state_ansi": "CA",
        "timezone": "America/Los_Angeles",
        "time": "13:51",
        "time24": "13:51:13",
        "time12": "01:51:13 PM",
        "date": "2026-10-26",
        "day": "Monday",
        "month": "October",
        "year": "2026",
        "unix": "1793047873",
        "dst": true,
        "dst_start": "2026-03-08 03:00:00",
        "dst_end": "2026-11-01 01:00:00",
        "dst_name": "PDT",
        "utc_offset": "-07:00",
        "datetime": "2026-10-26T13:51:13-07:00",
        "utc_datetime": "2026-10-26T20:51:13Z",
        "day_of_year": 299,
        "week_number": 44
      }
    ]
  }
}

Build your own with World Time. Start with 200 free credits. One key unlocks all 300+ APIs.

Explore the catalog

300+ APIs on the same key and the same response shape.

Browse all APIs