时间格式化

This commit is contained in:
cwchen 2025-11-24 10:31:43 +08:00
parent 2e3c457952
commit 7cbd2bfe98
1 changed files with 64 additions and 63 deletions

View File

@ -230,9 +230,10 @@ export function blobValidate(data) {
// 将年月日格式转换为yyyy-MM-dd格式
export function formatDate(dateStr) {
if (!dateStr) return '';
const cleanedStr = dateStr.replace(/\s/g, '');
// 提取年、月、日
const match = dateStr.match(/(\d{4})年(\d{1,2})月(\d{1,2})日/);
if (!match) return dateStr;
const match = cleanedStr.match(/(\d{4})年(\d{1,2})月(\d{1,2})日/);
if (!match) return cleanedStr;
const year = match[1];
const month = match[2].padStart(2, '0'); // 月份补零
const day = match[3].padStart(2, '0'); // 日期补零