diff --git a/utils/class/date.js b/utils/class/date.js index 36b21ce..06a270b 100644 --- a/utils/class/date.js +++ b/utils/class/date.js @@ -125,9 +125,13 @@ function pubTime(time, isOffset = false, format = null) { * @param {string|number} dateTimeStr 接口返回的时间和日期 */ function convertTo12HourFormat(dateTimeStr) { + var date // 解析输入的日期时间字符串 - const date = new Date(dateTimeStr.replace(' ', 'T')); // 使用 T 将字符串转换为 ISO 格式 - + if(new Date(dateTimeStr.replace(' ', 'T'))=='Invalid Date'){ + date = new Date(dateTimeStr); + }else{ + date = new Date(dateTimeStr.replace(' ', 'T')); + } // 获取各个部分 const year = date.getFullYear(); const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份要加1,并填充为2位