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.
| SHORT | MEDIUM | LONG_WITH_TIME | CUSTOM | |
|---|---|---|---|---|
| en-US | 10/19/26 | Oct 19, 2026 | October 19, 2026 at 8:32 AM | 10/19 |
| en-UK | 19/10/2026 | 19 Oct 2026 | 19 October 2026 at 08:32 | 19/10 |
| fr-FR | 19/10/2026 | 19 oct. 2026 | 19 octobre 2026 à 08:32 | 19/10 |
| it-IT | 19/10/26 | 19 ott 2026 | 19 ottobre 2026 alle ore 08:32 | 19/10 |
| de-DE | 19.10.26 | 19.10.2026 | 19. Oktober 2026 um 08:32 | 19.10. |
| es-ES | 19/10/26 | 19 oct 2026 | 19 de octubre de 2026 a las 8:32 | 19/10 |
import { useDateFormatter, DATE_FORMAT } from "@spendesk/grapes";
export default function ProductPage() {
const dateFormatter = useDateFormatter();
return <p>{dateFormatter(new Date(), DATE_FORMAT.MEDIUM)}</p>;
}
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>
);
}
import { dateFormatter } from "@spendesk/grapes";
export function localeFormat(locale) {
const formattedDate = dateFormatter(locale, new Date(), DATE_FORMAT.MEDIUM);
return formattedDate;
}