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/9/25 | Oct 9, 2025 | October 9, 2025 at 10:20 AM | 10/09 |
en-UK | 09/10/2025 | 9 Oct 2025 | 9 October 2025 at 10:20 | 09/10 |
fr-FR | 09/10/2025 | 9 oct. 2025 | 9 octobre 2025 à 10:20 | 09/10 |
it-IT | 09/10/25 | 9 ott 2025 | 9 ottobre 2025 alle ore 10:20 | 09/10 |
de-DE | 09.10.25 | 09.10.2025 | 9. Oktober 2025 um 10:20 | 09.10. |
es-ES | 9/10/25 | 9 oct 2025 | 9 de octubre de 2025, 10:20 | 9/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;
}