useFormatters

Hook for formatting dates, times, and datetimes with timezone conversion support.

This hook returns a formatDate function that you can use to format values depending on the type you provide (date, time, or datetime).

It automatically applies:

  • System-defined formats (from context) OR your custom format strings.

  • Timezone conversion (site, browser, or custom offset).

  • Optional seconds in time outputs.

Installation

import { useFormatters } from 'uxp/components';

Signature

function useFormatters(): { formatDate: (date: string | Date, options: ExtendedFormatOptions) => string; }

Examples

tsx
// Import the hook and get the formatDate function
import { useFormatters } from '@/hooks/useFormatters';

const { formatDate } = useFormatters();
const now = new Date();

Last updated