forked from UKSOURCE/hailearning.edu.vn
feat: Refactor blog components and add pagination
This commit is contained in:
21
utils/date.ts
Normal file
21
utils/date.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Format a date to `20 March 2025` style.
|
||||
*
|
||||
* Accepts:
|
||||
* - ISO string: "2025-03-20T07:59:53.219Z"
|
||||
* - "2025-03-20" or other Date‑parsable 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",
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user