* @description 格式化日期时间 * @param time * @returns * @example * formatDateTime() -> "2022-09-01 08:00:00" * formatDateTime(new Date()) -> "2022-09-01 08:00:00" * formatDateTime(Date.now()) -> "2022-09-01 08:00:00"
(time = Date.now())
| 2367 | * formatDateTime(Date.now()) -> "2022-09-01 08:00:00" |
| 2368 | */ |
| 2369 | function formatDateTime(time = Date.now()) { |
| 2370 | const date = new Date(time); |
| 2371 | const s = date.getSeconds(); |
| 2372 | const min = date.getMinutes(); |
| 2373 | const h = date.getHours(); |
| 2374 | const d = date.getDate(); |
| 2375 | const m = date.getMonth() + 1; |
| 2376 | const y = date.getFullYear(); |
| 2377 | // 日期 |
| 2378 | const dateText = [y, m, d].map(formatDateNum).join('-'); |
| 2379 | // 时间 |
| 2380 | const timeText = [h, min, s].map(formatDateNum).join(':'); |
| 2381 | // 日期时间 |
| 2382 | const dateTimeText = `${dateText} ${timeText}`; |
| 2383 | return dateTimeText; |
| 2384 | } |
| 2385 | /** |
| 2386 | * @description 格式化时间 |
| 2387 | * @param time |
no outgoing calls
no test coverage detected