14 lines
473 B
JavaScript
14 lines
473 B
JavaScript
// Backend datetime values are stored as UTC. Older records omit the timezone suffix.
|
|
export function formatDateTime(value, options = {}) {
|
|
if (!value) return "--";
|
|
const raw = String(value);
|
|
const normalized = /(?:Z|[+-]\d{2}:?\d{2})$/i.test(raw) ? raw : `${raw}Z`;
|
|
const date = new Date(normalized);
|
|
if (Number.isNaN(date.getTime())) return "--";
|
|
return date.toLocaleString("zh-CN", {
|
|
hour12: false,
|
|
timeZone: "Asia/Shanghai",
|
|
...options,
|
|
});
|
|
}
|