@vectara/vectara-ui
Version:
Vectara's design system, codified as a React and Sass component library
16 lines (15 loc) • 424 B
JavaScript
export const formatDate = (date, hasTime = false, showSeconds = true) => {
const options = {
year: "numeric",
month: "long",
day: "numeric"
};
if (hasTime) {
options.hour = "numeric";
options.minute = "2-digit";
if (showSeconds) {
options.second = "2-digit";
}
}
return Intl.DateTimeFormat(navigator.language, options).format(date);
};