added data table, formatter
revert context on __root beforeLoad refactor project structure refactor role badge dynamic nav menu
This commit is contained in:
20
src/utils/formatters.ts
Normal file
20
src/utils/formatters.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { getLocale } from '@/paraglide/runtime';
|
||||
|
||||
const locale = getLocale() === 'vi' ? 'vi-VN' : 'en-US';
|
||||
|
||||
export const formatters = {
|
||||
dateTime: (v: string | Date) => {
|
||||
const parts = new Intl.DateTimeFormat(locale, {
|
||||
day: '2-digit',
|
||||
month: '2-digit',
|
||||
year: 'numeric',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
hour12: true,
|
||||
}).formatToParts(new Date(v));
|
||||
|
||||
const map = Object.fromEntries(parts.map((p) => [p.type, p.value]));
|
||||
|
||||
return `${map.day}/${map.month}/${map.year} ${map.hour}:${map.minute} ${map.hour12 ? 'AM' : 'PM'}`;
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user