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 | 4/27/26 | Apr 27, 2026 | April 27, 2026 at 8:46 AM | 04/27 |
| en-UK | 27/04/2026 | 27 Apr 2026 | 27 April 2026 at 08:46 | 27/04 |
| fr-FR | 27/04/2026 | 27 avr. 2026 | 27 avril 2026 à 08:46 | 27/04 |
| it-IT | 27/04/26 | 27 apr 2026 | 27 aprile 2026 alle ore 08:46 | 27/04 |
| de-DE | 27.04.26 | 27.04.2026 | 27. April 2026 um 08:46 | 27.04. |
| es-ES | 27/4/26 | 27 abr 2026 | 27 de abril de 2026 a las 8:46 | 27/4 |
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;
}