fix: 修复日期格式化函数,支持不带前导零的 M/D 格式

- 修改 formatDateStr 函数,添加对 M/ 和 /D 格式的支持
- 确保生成的日期格式与后端期望的 yyyy/M/d HH:mm:ss 格式匹配
This commit is contained in:
2026-04-03 11:02:58 +08:00
parent 6fa26e895d
commit 3b0a359412

View File

@@ -29,10 +29,17 @@ export function formatDateStr(cellValue, format = 'YYYY-MM-DD HH:mm:ss') {
const minutes = String(date.getMinutes()).padStart(2, '0');
const seconds = String(date.getSeconds()).padStart(2, '0');
// 支持不带前导零的格式
const monthNoPad = String(date.getMonth() + 1);
const dayNoPad = String(date.getDate());
return format
.replace('YYYY', year)
.replace('MM', month)
.replace('DD', day)
.replace('M/', monthNoPad + '/') // 支持 M/ 格式
.replace('D ', dayNoPad + ' ') // 支持 D 格式(后跟空格)
.replace('/D', '/' + dayNoPad) // 支持 /D 格式
.replace('HH', hours)
.replace('mm', minutes)
.replace('ss', seconds);