Skip to main content
sunpeak API

Overview

The useTimeZone hook returns the user’s time zone from the host. It is a convenience wrapper around useHostContext.

Wraps onhostcontextchanged

MCP Apps SDK reference

Import

import { useTimeZone } from 'sunpeak';

Signature

function useTimeZone(): string

Returns

return
string
IANA time zone string (e.g., 'America/New_York'). Falls back to the browser’s local time zone when the host does not report one.

Usage

import { useTimeZone } from 'sunpeak';

function MyResource() {
  const timeZone = useTimeZone();

  const time = new Date().toLocaleTimeString('en-US', { timeZone });
  return <p>Current time: {time}</p>;
}
The time zone value comes from McpUiHostContext.timeZone.