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 | 5/4/26 | May 4, 2026 | May 4, 2026 at 4:27 PM | 05/04 |
| en-UK | 04/05/2026 | 4 May 2026 | 4 May 2026 at 16:27 | 04/05 |
| fr-FR | 04/05/2026 | 4 mai 2026 | 4 mai 2026 à 16:27 | 04/05 |
| it-IT | 04/05/26 | 4 mag 2026 | 4 maggio 2026 alle ore 16:27 | 04/05 |
| de-DE | 04.05.26 | 04.05.2026 | 4. Mai 2026 um 16:27 | 04.05. |
| es-ES | 4/5/26 | 4 may 2026 | 4 de mayo de 2026 a las 16:27 | 4/5 |
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;
}