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/30/25 | Oct 30, 2025 | October 30, 2025 at 4:30 PM | 10/30 |
| en-UK | 30/10/2025 | 30 Oct 2025 | 30 October 2025 at 16:30 | 30/10 |
| fr-FR | 30/10/2025 | 30 oct. 2025 | 30 octobre 2025 à 16:30 | 30/10 |
| it-IT | 30/10/25 | 30 ott 2025 | 30 ottobre 2025 alle ore 16:30 | 30/10 |
| de-DE | 30.10.25 | 30.10.2025 | 30. Oktober 2025 um 16:30 | 30.10. |
| es-ES | 30/10/25 | 30 oct 2025 | 30 de octubre de 2025, 16:30 | 30/10 |
import { useDateFormatter, DATE_FORMAT } from "@dev-spendesk/grapes";
export default function ProductPage() {
const dateFormatter = useDateFormatter();
return <p>{dateFormatter(new Date(), DATE_FORMAT.MEDIUM)}</p>;
}
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>
);
}
import { dateFormatter } from "@dev-spendesk/grapes";
export function localeFormat(locale) {
const formattedDate = dateFormatter(locale, new Date(), DATE_FORMAT.MEDIUM);
return formattedDate;
}