Grapes homepage1.64.2
  • 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-US5/4/26May 4, 2026May 4, 2026 at 4:27 PM05/04
    en-UK04/05/20264 May 20264 May 2026 at 16:2704/05
    fr-FR04/05/20264 mai 20264 mai 2026 à 16:2704/05
    it-IT04/05/264 mag 20264 maggio 2026 alle ore 16:2704/05
    de-DE04.05.2604.05.20264. Mai 2026 um 16:2704.05.
    es-ES4/5/264 may 20264 de mayo de 2026 a las 16:274/5

    Example

    import { useDateFormatter, DATE_FORMAT } from "@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 "@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 "@spendesk/grapes";
    
    export function localeFormat(locale) {
      const formattedDate = dateFormatter(locale, new Date(), DATE_FORMAT.MEDIUM);
      return formattedDate;
    }