hy2-panel/lib/datetime.ts
2026-05-06 00:10:45 +08:00

20 lines
419 B
TypeScript

export function formatLocalDateTime(value: string | null | undefined, fallback = "无") {
if (!value) {
return fallback;
}
const date = new Date(value);
if (Number.isNaN(date.getTime())) {
return fallback;
}
return new Intl.DateTimeFormat("zh-CN", {
year: "numeric",
month: "2-digit",
day: "2-digit",
hour: "2-digit",
minute: "2-digit",
hour12: false,
}).format(date);
}