Files
video-gen/video-gen-admin/src/utils/formatDate.ts
T
2026-05-25 17:08:18 +08:00

12 lines
500 B
TypeScript

export function formatDate(iso: string | null | undefined): string {
if (!iso) return '-';
let s = iso.trim();
if (!s.includes('T')) s = s.replace(' ', 'T');
// Truncate microseconds: 2026-05-13T15:04:04.313751 → 2026-05-13T15:04:04
const dotIdx = s.indexOf('.');
if (dotIdx > 0) s = s.slice(0, dotIdx);
// Remove any trailing timezone info (backend now sends naive datetimes)
s = s.replace(/[+-]\d{2}:?\d{0,2}$/, '').replace(/Z$/, '');
return s.replace('T', ' ').slice(0, 16);
}