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 | 8/18/26 | Aug 18, 2026 | August 18, 2026 at 12:42 PM | 08/18 |
| en-UK | 18/08/2026 | 18 Aug 2026 | 18 August 2026 at 12:42 | 18/08 |
| fr-FR | 18/08/2026 | 18 août 2026 | 18 août 2026 à 12:42 | 18/08 |
| it-IT | 18/08/26 | 18 ago 2026 | 18 agosto 2026 alle ore 12:42 | 18/08 |
| de-DE | 18.08.26 | 18.08.2026 | 18. August 2026 um 12:42 | 18.08. |
| es-ES | 18/8/26 | 18 ago 2026 | 18 de agosto de 2026 a las 12:42 | 18/8 |
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;
}