Files
uldp.edu.vn/utils/date.ts

22 lines
494 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* Format a date to `20 March 2025` style.
*
* Accepts:
* - ISO string: "2025-03-20T07:59:53.219Z"
* - "2025-03-20" or other Dateparsable strings
* - Date instance
*/
export function formatLongDate(input: string | Date): string {
if (!input) return "";
const date = input instanceof Date ? input : new Date(input);
if (Number.isNaN(date.getTime())) return "";
return date.toLocaleDateString("en-GB", {
day: "numeric",
month: "long",
year: "numeric",
});
}