29 lines
638 B
TypeScript
29 lines
638 B
TypeScript
export function formatDateTime(value?: string) {
|
|
if (!value) {
|
|
return '';
|
|
}
|
|
|
|
const time = Date.parse(value);
|
|
if (Number.isNaN(time)) {
|
|
return value;
|
|
}
|
|
|
|
return new Intl.DateTimeFormat('zh-CN', {
|
|
year: 'numeric',
|
|
month: '2-digit',
|
|
day: '2-digit',
|
|
hour: '2-digit',
|
|
minute: '2-digit',
|
|
hour12: false,
|
|
}).format(new Date(time));
|
|
}
|
|
|
|
export function getLatestDate(values: string[]) {
|
|
const timestamps = values.map((value) => Date.parse(value)).filter((value) => !Number.isNaN(value));
|
|
if (timestamps.length === 0) {
|
|
return '';
|
|
}
|
|
|
|
return new Date(Math.max(...timestamps)).toISOString();
|
|
}
|