Skip to content
View as Markdown

useTimeZone ​

React hook that returns a TimeZone object for the timezone configured on AppShell. Falls back to the user's local timezone when no timezone is configured.

Date/time components (DateField, DatePicker, Calendar) consume this hook automatically — use it when you need the same timezone in custom components.

For the current date or time in React components, use timeZone.today() or timeZone.now() rather than importing standalone today or now helpers from AppShell. These methods respect AppShell's timeZone setting; calculating against the browser's timezone directly can produce a different date.

Both methods read the current clock when called. They do not schedule re-renders when the date or time changes.

Signature ​

typescript
const useTimeZone: () => TimeZone;

Return Value ​

A TimeZone object with the following properties:

value ​

  • Type: string
  • Description: Raw IANA timezone identifier (e.g. "America/Los_Angeles"). Returns the value of AppShell's timeZone prop when configured, or the result of getLocalTimeZone() (the user's local timezone) when not.

today() ​

  • Type: () => CalendarDate
  • Description: Returns today's date in this timezone.

now() ​

  • Type: () => ZonedDateTime
  • Description: Returns the current instant in this timezone.

Usage ​

Import Text and useTimeZone from @tailor-platform/app-shell.

tsx
function TodayDisplay() {
  const timeZone = useTimeZone();
  const todayDate = timeZone.today();
  return <Text.span>Today: {todayDate.toString()}</Text.span>;
}

Current timestamp ​

The timestamp is read when the component renders; this is not an automatically updating clock.

tsx
function CurrentTimestamp() {
  const timeZone = useTimeZone();
  return <Text.span>{timeZone.now().toString()}</Text.span>;
}

Accessing the raw IANA string ​

tsx
function TimeZoneLabel() {
  const { value } = useTimeZone();
  return <Text.span>Timezone: {value}</Text.span>;
}
  • AppShell — configure timezone via the timeZone prop
  • useResolvedLocale — access the locale for formatting
  • DatePicker — date input components that consume this timezone automatically