Grapes homepage1.57.0
  • Guide
  • Tokens
  • Components
    Grapes on GithubGrapes on Figma
    Interaction
    • Button
    • IconButton
    • FloatingActionBar
    • Link
    Icons
    • Icon
    • HighlightIcon
    Form
    • AmountInput
    • Autocomplete
    • AutocompleteMultiple
    • AutocompletePlace
    • CheckboxBox
    • CheckboxField
    • DatePicker
    • FormField
    • Input
    • OptionGroup
    • PasswordInput
    • PhoneInput
    • RadioBox
    • RadioField
    • RadioGroup
    • Select
    • SwitchField
    • TextArea
    • TextInput
    • Upload
    • UploadButton
    Feedback
    • Badge
    • Banner
    • Callout
    • EmptyState
    • Modal
    • ModalSlideshow
    • DeprecatedModalSlideshow
    • PageModal
    • Skeleton
    • Tag
    • Toast
    • Tooltip
    Data display
    • Accordion
    • Avatar
    • Box
    • Calendar
    • CalendarRange
    • CollapsibleList
    • FileCard
    • InfoTip
    • ListBox
    • ListView
    • Panel
    • SidePanel
    • DeprecatedPreview
    • Table
    • Timeline
    • useDateFormatter
    Navigation
    • DropdownItem
    • DropdownMenu
    • Navigation
    • NavigationItem
    • Popover
    • Tabs

    useDateFormatter

    useDateFormatter is a hook providing localized date for the current locale. It is built around the native Intl.DateTimeFormat API with predefined date formats but can also be used using the same API.

    See the MDN docs for full details on how to use the API.

    useDateFormatter is built on top of the function dateFormatter. This function can also be used to format a date.

    Format Output

    SHORTMEDIUMLONG_WITH_TIMECUSTOM
    en-US12/16/25Dec 16, 2025December 16, 2025 at 3:28 PM12/16
    en-UK16/12/202516 Dec 202516 December 2025 at 15:2816/12
    fr-FR16/12/202516 déc. 202516 décembre 2025 à 15:2816/12
    it-IT16/12/2516 dic 202516 dicembre 2025 alle ore 15:2816/12
    de-DE16.12.2516.12.202516. Dezember 2025 um 15:2816.12.
    es-ES16/12/2516 dic 202516 de diciembre de 2025, 15:2816/12

    Example

    import { useDateFormatter, DATE_FORMAT } from "@dev-spendesk/grapes";
    
    export default function ProductPage() {
      const dateFormatter = useDateFormatter();
    
      return <p>{dateFormatter(new Date(), DATE_FORMAT.MEDIUM)}</p>;
    }
    

    Example with Intl.DateTimeFormat options

    import { useDateFormatter, DATE_FORMAT } from "@dev-spendesk/grapes";
    
    export default function ProductPage() {
      const dateFormatter = useDateFormatter();
    
      return (
        <p>
          {dateFormatter(new Date(), DATE_FORMAT.CUSTOM, {
            day: "2-digit",
            month: "2-digit",
          })}
        </p>
      );
    }
    

    Example using only dateFormatter

    import { dateFormatter } from "@dev-spendesk/grapes";
    
    export function localeFormat(locale) {
      const formattedDate = dateFormatter(locale, new Date(), DATE_FORMAT.MEDIUM);
      return formattedDate;
    }