| | |
| | | } |
| | | }, |
| | | |
| | | formatYMDH(date) { |
| | | formatYMDHM(date) { |
| | | if (date) { |
| | | return this.format(date, 'YYYY-MM-DD HH:mm'); |
| | | } else { |
| | | return '----/--/-- --:--'; |
| | | } |
| | | }, |
| | | |
| | | formatYMDHMS(date) { |
| | | if (date) { |
| | | return this.format(date, 'YYYY-MM-DD HH:mm:ss'); |
| | | } else { |
| | |
| | | const year = time.getFullYear(); |
| | | const month = time.getMonth() + 1; |
| | | const date = time.getDate(); |
| | | return ( |
| | | return dayjs( |
| | | year + |
| | | format + |
| | | (month < 10 ? '0' + month : month) + |
| | | format + |
| | | (date < 10 ? '0' + date : date) |
| | | ); |
| | | }, |
| | | |
| | | /** |
| | | * 将秒数转换为中文描述格式 |
| | | * @param {number} seconds - 秒数 |
| | | * @returns {string} 中文时间描述 |
| | | */ |
| | | formatSecondsToChinese(seconds) { |
| | | if (!seconds || seconds < 0 || isNaN(seconds)) { |
| | | return '--'; |
| | | } |
| | | |
| | | // 定义时间单位和对应的秒数 |
| | | const units = [ |
| | | { unit: '天', value: 24 * 60 * 60 }, |
| | | { unit: '小时', value: 60 * 60 }, |
| | | { unit: '分钟', value: 60 }, |
| | | { unit: '秒', value: 1 } |
| | | ]; |
| | | |
| | | let remainingSeconds = Math.floor(seconds); |
| | | let result = ''; |
| | | |
| | | // 遍历时间单位,计算每个单位的数量 |
| | | for (const { unit, value } of units) { |
| | | if (remainingSeconds >= value) { |
| | | const count = Math.floor(remainingSeconds / value); |
| | | result += `${count}${unit}`; |
| | | remainingSeconds %= value; |
| | | |
| | | // // 如果剩余秒数为0,且已经有结果,就可以结束了 |
| | | // if (remainingSeconds === 0 && result) { |
| | | // break; |
| | | // } |
| | | // 如果已经有结果,就可以结束了 |
| | | if (result) { |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | return result; |
| | | } |
| | | }; |
| | | }; |