ivy.rs/src/components/util/Date.astro
2025-03-17 12:49:54 +00:00

17 lines
410 B
Text

---
export interface Props {
date: string | Date;
}
const { date } = Astro.props;
if (!date) {
return null;
}
const dateObj = typeof date === "string" ? new Date(date) : date;
const options = { year: "numeric", month: "long", day: "numeric" };
const formattedDate = dateObj.toLocaleDateString("en-GB", options);
const isoDate = dateObj.toISOString();
---
<time datetime={isoDate}>{formattedDate}</time>